经纬度如何转换为1英里?

7

我正在使用谷歌地图,需要在一个邮编中心的5英里范围内进行搜索,因此我想到最简单的方法是找出纬度/经度转换为英里的方法。


这并不是一个真正的编程问题,也没有单一的转换方法。 - Matt Ball
谷歌的几何库可以为您计算距离。请访问此链接:http://code.google.com/apis/maps/documentation/javascript/geometry.html#Distance - Bryan Weaver
1个回答

7

使用Google几何库的基本思路如下。

请记得添加几何库,它与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,展示了这个功能的实际应用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接