【问题标题】:Google Maps - plot lines and distance (as the crow flies) between multiple latitude longitude pairs谷歌地图 - 绘制多个纬度经度对之间的线和距离(如乌鸦飞行)
【发布时间】:2011-03-10 22:35:21
【问题描述】:

我希望通过多个纬度经度对在地图上绘制一条“乌鸦飞翔”的路线。我还需要计算总距离(最好是点之间的距离)。

我找到了这个例子http://www.daftlogic.com/projects-advanced-google-maps-distance-calculator.htm,但它比我需要的复杂得多——我不需要任何类型的搜索功能,因为我已经有了我的纬度经度数据。但是,它显示路线的方式是我想要实现的目标

是否有任何更简单的示例可供我借鉴或实现此目标的任何一般指导?

【问题讨论】:

    标签: google-maps map google-maps-api-3


    【解决方案1】:

    “像乌鸦飞一样”绘制路线很容易,只需将折线的测地线选项设置为 true:

    var geodesic = new google.maps.Polyline({geodesic: true});
    

    您可以使用以下示例: http://code.google.com/apis/maps/documentation/javascript/examples/geometry-headings.html

    要计算距离,您可以使用 Google Maps API V3 的几何库。 http://code.google.com/apis/maps/documentation/javascript/geometry.html

    计算很简单:

    var distance = google.maps.geometry.spherical.computeDistanceBetween(latLngOfPointA, latLngOfPointB);
    

    要计算路径的长度,您可以使用 computeLength 函数:

    var path = geodesic.getPath();
    var length = google.maps.geometry.spherical.computeLength(path)
    

    【讨论】:

      【解决方案2】:

      确保在调用 Google Maps API 时包含几何库。

      Bootstrap from Documentation

      <script type="text/javascript"       src="http://maps.google.com/maps/api/js?libraries=geometry&sensor=true_or_false">  </script>
      

      【讨论】:

        【解决方案3】:

        我有一个包含 Vincenty 公式的 Excel 文件,我可以转发。 20000 公里精度优于 20 厘米。

        【讨论】:

          猜你喜欢
          • 2020-08-11
          • 1970-01-01
          • 2011-05-18
          • 1970-01-01
          • 1970-01-01
          • 2014-05-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多