我正在为iOS开发一个Codename One应用。 我正在使用MapContainer(https://github.com/codenameone/codenameone-google-maps),并为此设置了一个监听器,以便在用户按下的屏幕点上绘制标记。
这是代码段:
map.addTapListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
//Point of the screen where the user pressed
int x = evt.getX();
int y = evt.getY();
//I get the coordinates from the point of the screen
Coord coord = map.getCoordAtPosition(x, y);
//I create the marker, with a style
Style s = new Style();
s.setFgColor(0xff0000);
s.setBgTransparency(0);
FontImage markerImg = FontImage.createMaterial(FontImage.MATERIAL_PLACE, s);
EncodedImage icon = EncodedImage.createFromImage(markerImg, false);
map.addMarker(icon, coord, "My position", null, null);
map.zoom(coord, 15);
}
});
此代码无法将标记正确地放置在用户点击的点上:缺乏准确性。
根据这个问题(How to get my MapContainer bounding box in Codename One),我还尝试获取东北经纬度:
map.addTapListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
//I get the coordinates of the NE point
Coord neCoords = map.getBoundingBox().getNorthEast();
ToastBar.showMessage("NE coords: (" + neCoords.getLatitude() + ";" + neCoords.getLongitude() + ")", FontImage.MATERIAL_PLACE);
}
});
以下图片是iPhone的屏幕截图:
如您所见,东北角对应于via Ignazio Silone(图片中缺少“ Silone”)。摘录给出的坐标为:44.539829,11.367906。 我在Google Maps上放置了该坐标,然后将该位置与应用中显示的NE点进行了比较:如下图所示,它们有所不同(标记位于坐标44.539829,11.367906中,而箭头代表NE点显示在我的应用中)。
我该如何解决?我可以更准确地将标记放置在用户点击的位置吗?