我正在使用 Google map ,并且需要能够在邮政编码中心周围 5 英里半径内进行搜索,因此我认为最简单的方法就是计算出纬度/经度到英里的转换.
最佳答案
这是使用 Google's Geometry library 的基本思想。
记得添加几何库。它与 Google map 库是分开的。
<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这在行动中。
关于google-maps - 纬度/经度与 1 英里的换算是多少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8658730/