开发者

jxmapkit click event returning incorrect lat long

I am using JXmapkit in order to display a map with way points of openstreetmaps in a frame where the co-ordinates of the waypoint are stored within a database. When a location is clicked, the application will check whether the co-ordinates of the area is within the area around a waypoint, if true than an internal frame will open. The problem is that the co-ordinates of the clicked location are always returned incorrect example, the correct co-ordinates(35.9097,14.4259) are returned as (85.05012,-179.96198). I tried 开发者_JS百科to add the difference but it does not work as I cannot determine the exact difference between the co-ordinates since each time I click the same location, the co-ordinates always differ. Am I missing something or am I doing something wrong?

public static  ArrayList<StopBS> GetBusStopByCoordinates(float x, float y, float radius)
{
    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;
    try
    {
        ArrayList<StopBS> stops = new ArrayList<StopBS>();
        Class.forName("org.sqlite.JDBC");
        connection = DriverManager.getConnection(ConnectionString);
        statement = connection.createStatement(); 
       // Added value
       // x -= 49.1401725;
       // y += 194.4150295;
        float x1 = x - radius;
        float x2 = x + radius;
        float y1 = y - radius;
        float y2 = y + radius;
        String command = "SELECT StopID, StopNumber, Tag, Latitude, Longitude FROM StopTable  WHERE (Latitude BETWEEN %f AND %f) AND (Longitude BETWEEN %f AND %f)" ;
        command = String.format(command, x1,x2,y1,y2);
        resultSet = statement.executeQuery(command);
        while (resultSet.next())
        {
            StopBS newStop = new StopBS();
            newStop.StopID = resultSet.getInt("StopID");
            newStop.StopNumber = resultSet.getInt("StopNumber");
            newStop.Tag = resultSet.getString("Tag");
            newStop.Lat = resultSet.getFloat("Latitude");
            newStop.Long = resultSet.getFloat("Longitude");
            stops.add(newStop);
        }
        return stops;
    }
    catch (Exception e)
    {
        e.printStackTrace();
        return null;
    }
    finally
    {
        try
        {
            resultSet.close();
            statement.close();
            connection.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}
mainMap.getMainMap().addMouseListener(new MouseInputAdapter()
{      
        public void mouseClicked(MouseEvent e)
        {
           //Get mouse click position in screen values
            Point point = e.getPoint();
            //get map component
            JXMapViewer map = mainMap.getMainMap();
            //calculate x, y for map as the point is relative to the whole screen
           Rectangle bounds = getBounds();
            int x = (int)(point.getX() - bounds.getX());
            int y = (int)(point.getY() - bounds.getY());

            //Get the lat and long from the x and y mouse position
            Point2D pixelcoord1 = point;

           GeoPosition mappos =   map.getTileFactory().pixelToGeo(pixelcoord1, map.getZoom());
            Point2D QALLA =  map.getTileFactory().geoToPixel(mappos, map.getZoom());

           //check in database for busstops in that area 0.0015F
          ArrayList<StopBS> stops =  DataAccess.GetBusStopByCoordinates((float)mappos.getLatitude(),(float)mappos.getLongitude(), 0.0015F);
        }
    });
}    


jXMapKit1.getMainMap().convertPointToGeoPosition(pixelcoord1)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜