I use a latlngbound to show mutli markers on the map v2. And when I click either one of the markers, I want the camera to zoom in.
private void loadCenter(){
Builder boundsBuilder = new LatLngBounds.Builder();
for (int i=0;i<mmarker.saveMarker.size();i++)
{
boundsBuilder.include(mmarker.saveMarker.get(i));
}
LatLngBounds bounds = boundsBuilder.build();
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 60));
}
@Override
public boolean onMarkerClick(Marker mMarker) {
// TODO Auto-generated method stub
Toast.makeText(this, "MARKER CLICKED", Toast.LENGTH_LONG).show();
CameraUpdate zoom=CameraUpdateFactory.newLatLngZoom(mMarker.getPosition(), 15);
map.animateCamera(zoom);
return false;
}
I use the on marker click listener to detect the click on the marker. The toast in the method works. But the camera just won't zoom in, do you know why? thank you!
try:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
getMap().animateCamera(CameraUpdateFactory.newLatLngZoom(mk.getPosition(), level));
}
}, 300);
I was implementing something similar and came across the same problem and noticed that the api has some problems with timming the request. this worked for me.
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