【问题标题】:How can I get directions for multiple waypoints with different transit methods using the Google Directions Service?如何使用 Google 路线服务获取具有不同交通方式的多个航点的路线?
【发布时间】:2013-06-04 20:32:12
【问题描述】:

所以我了解如何使用 Google 路线服务来添加航点和更改交通模式,但是否可以使用同一个 API 调用来完成这两者?

我正在尝试获取涉及步行、骑自行车、然后再步行的路线,但我不确定如何使用一个 API 调用来完成。我知道我可以将它分成几部分,但它会迫使我处理 Google 的响应而不是使用 setDirections 方法。

这些是我要参考的文档:https://developers.google.com/maps/documentation/javascript/directions

【问题讨论】:

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


    【解决方案1】:

    但是是否可以使用同一个 API 调用来实现两者?

    暂时没有。

    然后它会强制我处理 Google 的响应而不是使用 setDirections 方法。

    你为什么这么说?除非您想做一些特别的事情,否则您应该能够使用 DirectionsRenderer 来显示多次调用 DirectionsService 的结果,方法是组合它们或为不同的部分使用不同的 DirectionRenderer 对象。

    【讨论】:

    • 也许我措辞不好。我希望将方向文本显示在像这样的 div 中-directionsDisplay.setPanel(document.getElementById("directions-panel"));不会多次调用它来覆盖它吗?我想我可以让它为每个调用写入 3 个不同的 div。
    • 这将是“针对不同部分的不同 DirectionRenderer 对象”的选项。如果将响应组合在一起并将它们传递给单个 DirectionsRenderer,则只需要一个(我没有这样做,但从概念上讲是可能的)。
    • 通过复制渲染器,我可以做到以下几点:dangoldin.com/citibike-station-directions 我知道它并不完美而且有点粗糙,但我会继续努力。
    猜你喜欢
    • 2019-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-01
    相关资源
    最近更新 更多