Can anyone help me to calculate or convert google map camera zoom level into KM distance . I want to send distance to api to get more pin data when user zoom out google map.
-
refer http://stackoverflow.com/questions/6002563/android-how-do-i-set-the-zoom-level-of-map-view-to-1-km-radius-around-my-curren – sasikumar Jan 05 '17 at 09:53
4 Answers
I have my simple conversion of zoom level
(zl) to km.
If zl1 = 40,000km
and zl2 = 20,000km
and so on. So every level will half the km.Therefore,
km = ( 40000/2 ^ zl ) * 2
e.g. zl = 4
km = (40000/2^4) * 2
= 5000km

- 990
- 1
- 10
- 29
-
2Great answer, thanks. The inverse of this (to get the amount of km covered by zoom level) is: `let zoom = getBaseLog(2, 40000 / (km / 2));` – Dara Java May 08 '20 at 04:02
-
-
1@LeresAldtai that's the default value of Google Maps' Zoom level to km. – lambda Sep 17 '21 at 09:38
-
Is that width or height of the current view area? I need to find the radius of the circumcircle of the view rectangle. – Oleg Lokshyn Mar 10 '22 at 18:10
-
@lambda, I have posted an updated solution with new google zoom level and taking latitude into account, thank you for giving me the inspiration – Eta Mar 15 '22 at 17:10
You can calculate the distance between the center of the map and the top left coordinate like this:
VisibleRegion visibleRegion = mMap.getProjection().getVisibleRegion();
double distance = SphericalUtil.computeDistanceBetween(
visibleRegion.farLeft, mMap.getCameraPosition().target);
Note that I'm using the SphericalUtil.computeDistanceBetween
method from the Google Maps Android API Utility Library.

- 18,044
- 4
- 45
- 61
-
i use this code but its give me 9504762.698378386 value at 2.0 zoom level but if we see Google Map app it give 2000 KM at full zoom out. Is this calculation is accurate ? – Zohaib Akram Jan 05 '17 at 10:18
-
1The `SphericalUtil.computeDistanceBetween` method uses the haversine formula to compute distances (https://en.wikipedia.org/wiki/Haversine_formula). In my case, using https://www.google.com/maps the distance measured between NY and Sydney is about 17000 Km, so it seems that the distance that you are getting is the expected order of magnitude (2000 Km is not) – antonio Jan 05 '17 at 10:51
-
Exactly what I was looking for! And I'd have needed this util library for clusterization anyway :) – Stephen Vinouze Apr 20 '22 at 15:39
I really like the simplicity of @lambda solution but it seems zoom levels have been rescaled.
When I do my tests I have zl3 = 38Mm , zl6 = 4.8Mm , zl9 = 600km ... BUT this is only reliable on the equator, you have to add another multiplier to account for latitude.
So my final formule looks like this :
km = (38000 / 2 ^ ( zl - 3)) * cos(lat)
with zl = map zoom level and lat = latitude of map's center in degre
For JS user you can copy this :
const km = 38000 / Math.pow(2, zl - 3) * Math.cos(lat * Math.PI / 180);
And now it is time to make the reverse formula :
zl = log2(38000 * cos(lat) / km) + 3
Which translate to JS as :
const zl = Math.log2(38000 * Math.cos ( lat * Math.PI / 180) / km) + 3
PS : I don't know if resolution have an impact, I am using a full HD screen (1920 x 1080)

- 12,090
- 1
- 70
- 92

- 334
- 3
- 9
-
Cool, I needed the reverse formula and this gave me a better zoom level approach than lambda's answer – Alter Lagos Apr 21 '22 at 06:09
A good start can be:
https://developers.google.com/maps/documentation/android-api/utility/#spherical
I myself use the SphericalUtil class but it's not accurate:
additional code :
private void animateToMeters(int meters, LatLng ll) {
int mapHeightInDP = 256;
Resources r = getResources();
int mapSideInPixels = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mapHeightInDP, r.getDisplayMetrics());
LatLngBounds latLngBounds = calculateBounds(ll, meters);
if (latLngBounds != null) {
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(latLngBounds, mapSideInPixels, mapSideInPixels, MARKER_BOUNDS);
if (gMap != null)
gMap.animateCamera(cameraUpdate);
}
}
@NonNull
private LatLngBounds calculateBounds(LatLng center, double radius) {
return new LatLngBounds.Builder().
include(SphericalUtil.computeOffset(center, radius, 0)).
include(SphericalUtil.computeOffset(center, radius, 90)).
include(SphericalUtil.computeOffset(center, radius, 180)).
include(SphericalUtil.computeOffset(center, radius, 270)).build();
}
private LatLng centerMapOnMyLocation() {
Location locationCt = getLastKnownLocation();
if (locationCt == null) {
return null;
}
LatLng latLng = new LatLng(locationCt.getLatitude(), locationCt.getLongitude());
.icon(BitmapDescriptorFactory.fromResource(android.R.drawable.ic_menu_add)));
gMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
return latLng;
}
Usage:
LatLng ll = centerMapOnMyLocation();
if (ll != null) {
animateToMeters(1500, ll);
}
EDIT
Zohaib Akram your result, 9504762.698378386, could be because map did not complete loading.
It you tailor your code to a button listener and click this button a few seconds later you will see different result.

- 2,376
- 2
- 24
- 38