Google Maps API v2 for Android: Marker and Polyline position mismatch

北战南征 提交于 2019-12-12 04:55:32

问题


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:

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

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)


回答1:


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).



来源:https://stackoverflow.com/questions/17725947/google-maps-api-v2-for-android-marker-and-polyline-position-mismatch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!