gpt4 book ai didi

google-maps - Google Maps API 可以计算沿多个位置或旅程段的路线吗?

转载 作者:行者123 更新时间:2023-12-04 12:46:14 24 4
gpt4 key购买 nike

我正在使用 Google Maps API 网络服务 Directions APIDistance Matrix API找出地点之间的旅行距离和时间。

API好像只支持计算一地一地的路线。 (在距离矩阵 API 的情况下,直接计算起点和终点之间的多个组合。)

我的情况是,我想知道沿着一系列(如有序数组)位置的多段旅程的路线(实际上,只是旅行时间和距离)。

所以,考虑到四个位置,ABCD,我知道如何计算A-BA-CA-DB-C 等之间的路由。我想计算 A-B-C-DA-C-D-BA-D-B-C 等的路线。我提供路线和腿的顺序,所以我不是要解决旅行商问题。

这可以通过 Google Maps Directions API 或 Distance Matrix API 实现吗?

显然,我可以自己链接这些位置,所以在单独的调用中询问各个路线的路线,然后按所需顺序将它们加在一起:A-C + C-D + D-B 变成 A-C-D-B。我希望这可以通过一个电话实现。

(我找过类似的问题,但没有找到确切的问题。)

最佳答案

感谢@geocodezip,答案是在起点和终点之间添加“航路点”,如 documentation of the Directions API 中所述.

例如,请求 https://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA计算波士顿和康科德之间经过查尔斯敦和列克星敦的路线。

旅行商问题也得到了部分解决,根据

By default, the Directions service calculates a route through the provided waypoints in their given order. Optionally, you may pass optimize:true as the first argument within the waypoints parameter to allow the Directions service to optimize the provided route by rearranging the waypoints in a more efficient order.

关于google-maps - Google Maps API 可以计算沿多个位置或旅程段的路线吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47224665/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com