0

I'm trying to draw some markers and a polyline in the same map this way

    MarkerOptions options = new MarkerOptions();
    Marker marker;

    PolylineOptions polyLineOptions = new PolylineOptions();
    polyLineOptions.color(context.getResources().getColor(R.color.mm_red));

    if (route != null) {

        for(Entry entry : route.getEntries().getEntryList()){

            LatLng pos = new LatLng(entry.getGeolocation().getLatitude(), entry.getGeolocation().getLongitude());
            options.position(pos);
            polyLineOptions.add(pos);

            marker = mMap.addMarker(options.icon(BitmapDescriptorFactory.fromResource(R.drawable.im_map_marker_main_num)));
            marker.setVisible(true);

        }


    Polyline polyline = mMap.addPolyline(polyLineOptions);
    polyline.setVisible(true);

    }

However, here you can see the result I get:

Markers and Polyline mismatch

As you can see, even if I pass the same LatLng position to both MarkerOptions and PolylineOptions, there is some kind of offset.

As extra information, I get this behaviour in a Nexus 7.

Thank you

Edit: The marker icon's pin location is the default one, so the center of the bottom side of it Default marker image

Edit: Not bitmap creation problem. If I use canvas.drawColor, this is what I get (different size, because now I'm with a Nexus 10)

drawcolor not working

Aitor Gómez
  • 7,317
  • 3
  • 20
  • 28

1 Answers1

4

The problem here is that by default, the pin location of the Marker is at the bottom center of the image.

You will have to fiddle with anchor(float, float) and / or make sure the sharp edge is the last pixel on the bottom center (with no transparent pixels below).

MaciejGórski
  • 22,187
  • 7
  • 70
  • 94
  • Hi MaciejGórski, All the icons I use have their pin position centered in the default place (the middle of the bottom size). Thank you :-) – Aitor Gómez Jul 18 '13 at 14:35
  • @Wakka You seem to be drawing this icon into `Bitmap`. Can you fill the background with `canvas.drawColor`? – MaciejGórski Jul 18 '13 at 20:47
  • @MaciejGórksi Thanks but it still doesn't work (look above in the second Edit) :-) – Aitor Gómez Jul 19 '13 at 07:35
  • At the end I solved it playing with anchor values. It's not the best solution, but it is the one that works. Thanks. – Aitor Gómez Jul 19 '13 at 11:52
  • @Wakka That's strange. Can you make a simple app on github to show the issue? Then maybe post on gmaps-api-issues if that is really not a problem with your code. – MaciejGórski Jul 19 '13 at 12:16