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" />
Just try to create the marker and set the draggable property to true . The code will be something as follows: Marker = new google.
The transition() and moveMarker() are used to move marker smoothly on click on the Google map.
A user can scroll (pan) around the map by dragging the map with their finger. You can disable scrolling by calling UiSettings. setScrollGesturesEnabled(boolean).
To fix Google maps zooming problems, for Google maps default zoom you want to know how to change the zoom level on Google Maps. You can change the zoom level by going to the Edit map page and then selecting 'default zoom level' in the map information section and then clicking save map.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With