I need to know how to retrieve the radius of the viewable zoom level in google maps API v3.
For example, if I am at zoom level 3, and depending on the users screen size (lets just say 400×400 viewable region) how do I get the "radius" circle of the viewable area.
Alternatively I'm currently using map.fitBounds() for all the points I've added to the map so really all I NEED is the radius of all the bounds. What I want is something like "20 miles" that I can feed into my database app.
Best Answer
The radius would equal the distance from the center of the bounds to one of the bound's corners. Using the Great Circle Distance Formula from the calculations from this page, I came up with the following:
After playing some more with this, I've noticed that
map.getBounds()
will contain the full map viewport. But if yourLatLngBounds
is built by extending to includeLatLng
points, and then you issue amap.fitBounds(bounds)
, the api increases the map's viewport a bit so that thebounds
"box" has some padding.If you use the map's current viewport, the radius from the center to the corner of the viewport might be a longer radius than you want. Maybe the distance from the viewport center to the middle of the furthest viewport edge. (If the map isn't a perfect square)