How does this Google Maps zoom level calculation work?
Some numbers can be explained easily
MeanRadiusEarthInKm = 6371 (according to IUGG)
DegToRadDivisor = 180/PI = 57.2958
And again the zoom level doubles the size with each step, i.e. increase the zoomlevel by one halfs the size on the screen.
zoom = 8 - log(factor * dist) / log(2) = 8 - log_2(factor * dist)
=> dist = 2^(8-zoom) / factor
From the numbers we find that zoom level eight corresponds to a distance of 276.89km.
I use a simple formula below:
public int getZoomLevel(Circle circle) {
if (circle != null){
double radius = circle.getRadius();
double scale = radius / 500;
zoomLevel =(int) (16 - Math.log(scale) / Math.log(2));
}
return zoomLevel;
}
You can also replace circle with its specific radius.