首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jxmapkit单击事件返回错误lat

jxmapkit单击事件返回错误lat
EN

Stack Overflow用户
提问于 2011-05-03 22:00:10
回答 1查看 1.7K关注 0票数 1

我使用JXmapkit是为了在一个框架中显示openstreetmaps的路点地图,其中路点的坐标存储在数据库中。当点击一个位置时,应用程序将检查该区域的坐标是否在航点周围的区域内,如果是真的,则内部框架将打开。问题是单击位置的坐标总是返回不正确的示例,正确的坐标(35.9097,14.4259)返回为(85.05012,-14.4259)。我试图添加差异,但它不起作用,因为我无法确定坐标之间的确切差异,因为每次我单击相同的位置,坐标总是不同。我是错过了什么,还是做错了什么?

代码语言:javascript
复制
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);
        }
    });
}    
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-22 14:22:30

jXMapKit1.getMainMap().convertPointToGeoPosition(pixelcoord1)

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5870618

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档