Markers move when zooming with Google Maps Android API v2
android, google-maps-android-api-2, google-maps-markers
Solution
For custom markers you need also use
`MarkerOptions.anchor(float u, float v)`
which describes where is the pointer point on the marker. By default this point is located at middle-bottom of the image.
Problem
When adding some markers on a map using Google Maps Android API v2, the markers are no set to the right positions and move when zooming. When zooming in they get closer to the right positions, as if they were translated by a factor related to the zoom. What's wrong? Example zooming in: 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" /> ```