I'm developing a Codename One app for iOS. I'm using a MapContainer (https://github.com/codenameone/codenameone-google-maps) and I set a tap listener for it, in order to draw a marker in the point of the screen pressed by the user.
This is the code snippet:
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);
}
});
This code does not correctly place the marker in the point tapped by the user: it lacks in accuracy.
According to this question (How to get my MapContainer bounding box in Codename One), I also tried to get the North-East latitude and longitude:
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);
}
});
The following picture is a screenshot from an iPhone:
As you can see, the North-East corner corresponds to via Ignazio Silone ("Silone" is missing in the picture). The coordinates the snippet gave are: 44.539829,11.367906. I put that coordinates on Google Maps and I compared that place with the NE point shown in my app: they differ, as you can see in the following picture (the marker is placed in the coordinates 44.539829,11.367906, while the arrow represents the NE point shown in my app).
How can I solve it? Can I place the marker in the position tapped by the user, with more accuracy?