SOLVED:
from the Androd google API: zoomlevel sets the scale of the map. The value will be sandwiched between 1 and 21 inclusive, although not all areas have tiles with a higher zoom level. It just sets the zoom level directly; Parameters: zoomLevel - When you zoom in 1, the Earth's equator is 256 pixels long. Each subsequent zoom level is increased by 2 times. Returns: a new zoom level from 1 to 21 inclusive.
So, taking into account the equator, E = 40,075 km or 21,638.8 miles, considering the distance to the zoom D = 20 km or miles
zoom level: L = log2 (E / D) +1
This is a simple method that I used do not forget to set E = 21.638.8 if you want to use miles ...
public static byte zoomLevel (double distance){ byte zoom=1; double E = 40075; Log.i("Astrology", "result: "+ (Math.log(E/distance)/Math.log(2)+1)); zoom = (byte) Math.round(Math.log(E/distance)/Math.log(2)+1);
source share