1

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?

A M
  • 831
  • 1
  • 14
  • 26
  • Is this on the simulator or on the device as well? If on the simulator can you turn off zoom and see if it impacts the behavior? – Shai Almog May 07 '19 at 02:56
  • It's on the device. – A M May 07 '19 at 06:10
  • 1
    I've built a sample, largely based off your code, and it seems to run OK in Simulator and on device (iPhone 8). Are you possibly using an old version of the GoogleMaps.cn1lib? Here is the sample https://github.com/codenameone/CodenameOne/blob/master/Samples/samples/GoogleMapsAddMarkerSample/GoogleMapsAddMarkerSample.java – steve hannah May 07 '19 at 12:27
  • @stevehannah you're right. After updating the library, it perfectly works! Thank you – A M May 07 '19 at 15:44

0 Answers0