【问题标题】:What is the conversion of latitude/longitude to a 1 mile [closed]纬度/经度到1英里的转换是多少[关闭]
【发布时间】:2011-12-28 16:45:02
【问题描述】:
我正在使用 Google 地图,我需要能够在邮政编码中心周围 5 英里的半径范围内进行搜索,因此我认为最简单的方法是计算纬度/经度到英里的转换.
【问题讨论】:
标签:
google-maps
math
google-maps-api-3
【解决方案1】:
这是使用Google's Geometry library 的基本思想。
记得添加几何库。它与 Google 地图库是分开的。
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false">
</script>
示例用法:
//the distance function defaults to km.
//to use miles add the radius of the earth in miles as the 3rd param.
//earths radius in miles == 3956.6
var distance =
google.maps.geometry.spherical.computeDistanceBetween(
/* from LatLng */,
/* to LatLng */,
/* radius of the earth */
);
if (distance <= 5) { //less or equal to five miles
var marker = new google.maps.Marker({
map: map,
position: //LatLng
});
}
我有一个示例 fiddle 正在使用中。