google-maps - 纬度/经度与 1 英里的换算是多少

标签 google-maps math google-maps-api-3

我正在使用 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/

相关文章:

ios - MKMapView 会在 iOS6 中自动使用谷歌地图,因为谷歌地图在 iOS6 中恢复了吗?

google-maps - 使用地址链接到街景 URL?

javascript - 难以从 'react-google-maps' 导入 SearchBox

java - 关于 Math.atan2 的保证

javascript - Google Maps API v3 : How do I pause/delay in Javascript to slow it down? 中的 OVER_QUERY_LIMIT

google-maps - 如何设置谷歌地图的大小不与 BottomNavigationBar 重叠

java - Java 中的方程式 - 输出为 0 或不正确的值

c++ - 我的代码不适用于大数字

google-maps - 解码谷歌地图嵌入参数

javascript - 聚合物谷歌地图 - 绘制形状