Reputation: 9643
I have implemented the below code for zooming on the location markers when user click on them. It works fine for almost all markers except the marker which are near the top or bottom of the map. Zooming for markers near top and bottom of map is not at exact place.As the map first animate the camera so that marker comes at the center of screen and then zoom at the center of screen, the markers near the top are not able to come at the center and that's why the zoom is not at the exact location.Is there any way I can resolve this?
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(final Marker marker) {
CameraUpdate center=
CameraUpdateFactory.newLatLng(marker.getPosition());
CameraUpdate zoom=CameraUpdateFactory.zoomTo(6);
});
I tried below code also but same issue-
googleMap.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition()));
googleMap.animateCamera(CameraUpdateFactory.zoomBy(2));
Upvotes: 0
Views: 177
Reputation: 6078
Try following method, I have tried and it works, can not tell if it meets you requirement:
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(final Marker marker) {
// CameraUpdate center=
// CameraUpdateFactory.newLatLng(marker.getPosition());
// CameraUpdate zoom = CameraUpdateFactory.zoomTo(6);
// return true;
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(marker.getPosition(),15));
// Zoom in, animating the camera.
googleMap.animateCamera(CameraUpdateFactory.zoomIn());
// Zoom out to zoom level 10, animating with a duration of 2 seconds.
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
return true;
}
});
Upvotes: 1