我正在使用谷歌地图,我需要能够在邮政编码中心周围的5英里半径内进行搜索,所以我想最简单的方法是计算出纬度/经度到英里的转换。
发布于 2011-12-29 01:41:05
下面是使用Google's Geometry library的基本思想。
记得添加几何库。它与谷歌地图库是分开的。
<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。
https://stackoverflow.com/questions/8658730
复制相似问题