【问题标题】:How to calculate distance between 2 places如何计算两个地方之间的距离
【发布时间】:2011-03-18 15:18:02
【问题描述】:

有人问我是否可以创建这样的网站:

我很好奇如何计算地点之间的距离。例如,如果我要在明尼阿波利斯的系统中输入一张美元钞票,然后该钞票由洛杉矶的另一个用户输入,我将如何计算那是多少英里?

我看过一点 Google 地图 API,但没有看到任何关于计算距离的内容。

【问题讨论】:

  • 你想要乌鸦飞还是路由距离?

标签: google-maps distance


【解决方案1】:

Google Map API 有一个功能可以找到这个。

GLatLng.distanceFrom()

【讨论】:

    【解决方案2】:

    获取两个位置的 GPS 坐标,然后在球体上的两个点之间使用formula for finding distance?那将是乌鸦飞行的距离。如果你想要最短的行驶距离,那就不一样了。

    【讨论】:

    • 好吧,地球是一个扁球体而不是球体。它在两极压扁。因此,要获得更准确的结果,您需要使用 Vincenty 公式计算两个纬度/经度点之间的距离。
    【解决方案3】:

    这里有一个解释,带有公式:http://en.wikipedia.org/wiki/Great-circle_distance

    【讨论】:

      【解决方案4】:

      您需要的是用于计算两个纬度/经度点之间距离的 Vincenty 公式的 JavaScript 实现。

      http://www.movable-type.co.uk/scripts/latlong-vincenty.html

      这很容易在谷歌地图中实现,如果需要,可以将两个 LatLng 坐标作为参数。

      例如,获取地图上最后点击的两点之间的距离:

      // requires distVincenty method from www.movable-type.co.uk/scripts/latlong-vincenty.html
      map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
      lastClickLatLng = false;
      google.maps.event.addListener(map, 'click', function (event) {
          if (lastClickLatLng) {
              var myDistance = distVincenty(lastClickLatLng.lat(), lastClickLatLng.lng(), event.latLng.lat(), event.latLng.lng());
              // Do something with myDistance!
          }
          lastClickLatLng = event.latLng;
      });
      

      【讨论】:

        【解决方案5】:

        伟业东的反应非常适合“乌鸦飞”的计算。 但是,如果您想通过步行或驾车了解距离,请使用 Google 的 Directions API - http://code.google.com/apis/maps/documentation/directions/

        【讨论】:

        • 我刚刚看到您正在寻找“如乌鸦飞”的董氏。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-12-21
        • 1970-01-01
        • 2019-02-16
        • 2016-07-01
        • 1970-01-01
        • 2011-12-24
        相关资源
        最近更新 更多