Android Google Maps v2 - set zoom level for myLocation
Solution 1:
It's doubtful you can change it on click with the default myLocation Marker. However, if you would like the app to automatically zoom in on your location once it is found, I would check out my answer to this question
Note that the answer I provided does not zoom in, but if you modify the onLocationChanged method to be like the one below, you can choose whatever zoom level you like:
@Override
public void onLocationChanged(Location location) {
if( mListener != null ) {
mListener.onLocationChanged( location );
//Move the camera to the user's location and zoom in!
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 12.0f));
}
}
Solution 2:
You can also use:
mMap.animateCamera( CameraUpdateFactory.zoomTo( 17.0f ) );
To just change the zoom value to any desired value between minimum value=2.0 and maximum value=21.0.
The API warns that not all locations have tiles at values at or near maximum zoom.
See this for more information about zoom methods available in the CameraUpdateFactory
.
Solution 3:
with location - in new GoogleMaps SDK:
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(chLocation,14));
Solution 4:
Here are the approximate zoom levels and what they do :
1: World
5: Landmass/continent
10: City
15: Streets
20: Buildings
so you could do something like this to zoom to street level for example (note the "15f" below is street level) :
override fun onMapReady(googleMap: GoogleMap?) {
googleMap?.mapType = GoogleMap.MAP_TYPE_NORMAL
googleMap?.addMarker(MarkerOptions()
.position(LatLng(37.4233438, -122.0728817))
.title("cool place")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ROSE)))
googleMap?.animateCamera(CameraUpdateFactory.newLatLngZoom(LatLng(37.4233438, -122.0728817), 15f))
note: just so you know different locations can have different max zoom levels. try to use googleMap.maxZoomLevel
if you want to get the max or min zoom levels.
Solution 5:
Slightly different solution than HeatfanJohn's, where I change the zoom relatively to the current zoom level:
// Zoom out just a little
map.animateCamera(CameraUpdateFactory.zoomTo(map.getCameraPosition().zoom - 0.5f));