Java Enthusiast Java Enthusiast - 1 month ago 8x
Android Question

Dynamic zoom in Google Maps API v2 Android

In Google Maps API v2, the method

is used to define the zoom level for viewing. For example,

googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat1, lng1), 12));

Here, the zoom level is fixed to 12. How do I make sure that the zoom value fixed here, will allow the user to view source and destination points along the route without manual zooming.

I know using trial and error methods and some
conditions, the values can be determined. But is there a more sophisticated way of doing this?


You can use LatLngBounds like this:

LatLngBounds.Builder builder = new LatLngBounds.Builder();
LatLngBounds bound =;
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bound, 25), 1000, null);

startPoint and endPoint are LatLng objects.