Fat Monk
Fat Monk

Reputation: 2265

Setting zoom level based on geolocation accuracy in Google Maps API v3

How can I calculate an appropriate zoom level to set in a Google Maps web application based on the accuracy value returned by HTML5 geolocation?

Essentially I want the map zoomed in far enough to show detail, but out far enough to show the area bounded by the accuracy radius (I'm drawing a circle around the centre-point to show the area that the user could be in).

I have found answers relating to using the maps API geocoding location_type but nothing relating to using the HTML5 geolocation accuracy value which is returned in metres.

I get the feeling setBounds might be one way to do it, but that involves converting meters to a new set of LatLng values which I get the feeling can be a bit vague (but maybe not so vague over the distances that the geolocator accuracy is likely to return).

Thanks,

Upvotes: 3

Views: 1724

Answers (2)

Arun Prasad E S
Arun Prasad E S

Reputation: 10125

This helped me

var zoomLevel = parseInt(Math.log2(591657550.5 / (accuracy * 45))) + 1;

This gives me reasonable zoom level based on accuracy. (haven't included pixel info for the calculation)

Upvotes: 2

Dr.Molle
Dr.Molle

Reputation: 117354

Draw the Circle and then use the bounds of the circle as argument for fitBounds

Upvotes: 3

Related Questions