Markers move when scaling with Google Maps Android API v2

When you add some markers to a map using the Google Maps v2 Android API, the markers are not set to the correct positions and do not move when scaling.

When scaling, they come closer to the correct positions, as if they were translated by a factor related to the increase.

What's wrong?

Scaling example:

enter image description hereenter image description hereenter image description here

fragment

public class CenterMapFragment extends Fragment { private GoogleMap mMap; private List<Center> mCenterList; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.center_map_fragment, container, false); } @Override public void onActivityCreated (Bundle savedInstanceState){ super.onActivityCreated(savedInstanceState); mMap = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map)) .getMap(); if (mMap != null) { mCenterList = MyApplication.dbHelper.getAllCenter(); for(Center center : mCenterList){ mMap.addMarker(new MarkerOptions().position(new LatLng(center.lat, center.lng)).icon(BitmapDescriptorFactory .fromResource(R.drawable.myicon))); } } } } 

layout

 <?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" /> 
+6
source share
2 answers

For custom markers you also need to use

MarkerOptions.anchor(float u, float v)

which describes where the pointer point is on the marker. By default, this point is located in the middle of the bottom of the image.

+5
source

To display window information, you need to use setInfoWindowAdapter on your "mMap" or provide a title for your marker.

About the icon, it seems to move when you zoom out, but the anchor always points to the same place on the map. You can set the snap if the image you are using does not match the Google icon template (anchor in the middle of the botton image). To do this, you need to use the anchor of the MarkerOptions (u, v) method

0
source

All Articles