Search code examples
javascripthtmlgoogle-maps-api-3geolocation

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,


Solution

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