How do I zoom in automatically to the current location in Google Maps API for Android?
Change from:
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
to:
float zoomLevel = 16.0f; //This goes up to 21
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoomLevel));
public static CameraUpdate newLatLngZoom (LatLng latLng, float zoom)
Returns a CameraUpdate that moves the center of the screen to a latitude and longitude specified by a LatLng object, and moves to the given zoom level.
Parameters latLng a LatLng object containing the desired latitude and longitude. zoom the desired zoom level, in the range of 2.0 to 21.0. Values below this range are set to 2.0, and values above it are set to 21.0. Increase the value to zoom in. Not all areas have tiles at the largest zoom levels. Returns a CameraUpdate containing the transformation.
or you can also use animateCamerma method to get an animated zooming effect.
// This is method returns the lastKnownlocation and store it in location object from where then you can retrive latitute and longitude.
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 20.0f));