Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Maps v2 custom marker has incorrect position on zoom

I know this has been discussed before, but I actually can't find a solution.

I am adding a custom icon for my marker:

markerUserLocation = mMap.addMarker(new
                        MarkerOptions().position(new
                                LatLng(point.latitude,
                                        point.longitude))
                                .anchor(0.5f, 1.0f)
                               .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_marker_my_location)));

The problem is when zooming in/out the marker gets positioned in a bad place.

I have tried to play with the anchor values, but no success. Isn't the default anchor mid/bottom of the image ? What i need to do, to actually keep the bottom of the marker at the specified point coordinates, independent of zooming level ?

Here is a ic_marker_my_location icon sample (xhdpi size), as I can't upload the original icon. enter image description here

LE: this is a really silly, but if i use a smaller marker image... it works correctly... So maybe there is a bug with marker resource image size ? Or if the image is bigger, I need to set some extra parameters ?

like image 895
Alin Avatar asked Jun 27 '13 08:06

Alin


People also ask

How do I change marker positions?

Call the changeMarkerPosition() function and pass the marker object in it. The setPosition() will change the marker position on google map based on the specified latitude and longitude.

How do I drag a marker on Google Maps Android?

Long press the marker to enable dragging. When you take your finger off the screen, the marker will remain in that position. Markers are not draggable by default. You must explicitly set the marker to be draggable either with MarkerOptions.

How do I get a marker position on Google Maps?

You can add a simple marker to the map at a desired location by instantiating the marker class and specifying the position to be marked using latlng, as shown below.

How do you change markers on Google Maps?

Click or tap on the Edit option to open a small box with different sections labeled Title and Description as well as a marker icon. To edit the marker color, click or tap on the marker icon. When you do that, you can change both the color of the marker and its style.


1 Answers

I recently experienced a similar issue. It seems to me that there is a bug with the setIcon(Bitmap bitmap) function of the marker.

As soon as i change the image of the marker, the anchor is messed up, so I had to reset it again to the default position.

marker.setIcon(bitmap);
marker.setAnchor(0.5f,1f);

That worked for me using the play services (8.4.0)

like image 74
Mike T Avatar answered Sep 25 '22 15:09

Mike T