【问题标题】:Find the direction of a path using Google Direction API使用 Google Direction API 查找路径的方向
【发布时间】:2014-03-25 02:49:08
【问题描述】:

我正在使用 Google Places API 和方向 API 来标记 2 个地点之间的路线。我得到这条路线的折线。现在我有另一条折线位于这条路线上。

例如:点 A 到点 B -> 初始折线 点 C 到点 D -> 位于 A->B 多段线上的第二条多段线。

使用 isLocationOnEdge() 方法,我能够找出 C->D 折线是否位于 A->B 折线上。

问题是我想知道路径 C->D 是在 A->B 的方向还是相反的方向。有没有办法做到这一点?

【问题讨论】:

    标签: google-maps google-maps-api-3 google-places-api google-directions-api


    【解决方案1】:

    使用geometry library,您可以使用computeHeading 方法。请参阅the documentation

    因此,您可以计算点 A 和 B 之间的航向,并将其与点 C 到 D 的航向进行比较。

    var heading = google.maps.geometry.spherical.computeHeading(path.getAt(0), path.getAt(1));
    

    path 是您的第一条折线。然后对第二个做同样的事情并比较结果。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-08
      • 1970-01-01
      • 1970-01-01
      • 2013-06-03
      • 1970-01-01
      • 2013-04-06
      相关资源
      最近更新 更多