I want to set the map view zoomed to 1km radius but cant figure out how?
The doc says that the zoom level 1 will map earths equator to 256 pixels. So how do I calcul
I've converted the accepted answer to return a double value, since the Android Google Maps library uses floating point zoom levels, and also account for latitudes away from the equator.
public static double getZoomForMetersWide (
final double desiredMeters,
final double mapWidth,
final double latitude )
{
final double latitudinalAdjustment = Math.cos( Math.PI * latitude / 180.0 );
final double arg = EQUATOR_LENGTH * mapWidth * latitudinalAdjustment / ( desiredMeters * 256.0 );
return Math.log( arg ) / Math.log( 2.0 );
}
As an aside, for best results on Android don't pass the view's real pixel count, but the dimension scaled for the device's pixel density.
DisplayMetrics metrics = getResources().getDisplayMetrics();
float mapWidth = mapView.getWidth() / metrics.scaledDensity;
Hope this helps someone.