2011-12-28 55 views
7

我与谷歌地图的工作转换,我需要能够在周围邮政编码中心方圆5英里搜寻,因此我想做到这一点的最简单的方法将要弄清楚纬度/经度转换为英里。什么是纬度/经度来有1英里的

+0

这是不是一个真正的编程问题,并没有一个统一的转换。 – 2011-12-28 16:47:06

+0

[Google的几何库](http://code.google.com/apis/maps/documentation/javascript/geometry.html#Distance)可以为您计算距离。 – 2011-12-28 16:49:47

回答

3

谷歌是你的朋友。 “经纬度转换为英里”的前几个结果中发现这一点:http://www.movable-type.co.uk/scripts/latlong.html

它甚至还给出了一些JavaScript代码。只需注意一下,它在KM中给出结果,但可以很容易地将其转换为英里。

7

下面是使用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在行动。