[英]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?如何根据 HTML5 地理定位返回的精度值计算要在 Google 地图 Web 应用程序中设置的适当缩放级别?
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.我找到了与使用地图 API 地理编码 location_type 相关的答案,但与使用以米为单位返回的 HTML5 地理定位精度值无关。
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).我觉得 setBounds 可能是一种方法,但这涉及将米转换为一组新的 LatLng 值,我觉得这可能有点模糊(但在地理定位器精度可能的距离上可能不那么模糊返回)。
Thanks,谢谢,
绘制Circle
,然后使用圆的bounds
作为fitBounds
参数
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)
(没有包括计算的像素信息)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.