您可以使用单个 API 呼叫获得多个目的地的理想路线吗?
Can you get an ideal route of multiple destinations using a single API call?
我想看看是否有办法在单个 API 调用中找到 X 个目的地之间的理想路线,顺序无关紧要。
例如,程序有 3 个目的地,Jeff 家、Amy 家和 Valerie 家。不太在意我们进去的顺序,但我们希望用最少的车程参观每个房子。
现在,我已将其设置为我们尝试每一个目的地的排序,并确定用时最快的那个。但是有这么多 API 调用似乎效率低下,但我在 API 中看不到一种方法来做我想做的事。在 google 地图 API 中,我目前想要的是可能的吗?
您可以在路线 API 网络服务中使用 Waypoints,其中 returns 包括在中间位置经过或中途停留的路线。
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.
示例请求:
https://maps.googleapis.com/maps/api/directions/json?
origin=Adelaide,SA&destination=Adelaide,SA
&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA
&key=YOUR_API_KEY
请注意,使用航点优化的请求按 higher rate 收费。
如果您将使用 client-side 地图 JavaScript 路线服务。参考这个documentation and example.
希望对您有所帮助!
我想看看是否有办法在单个 API 调用中找到 X 个目的地之间的理想路线,顺序无关紧要。
例如,程序有 3 个目的地,Jeff 家、Amy 家和 Valerie 家。不太在意我们进去的顺序,但我们希望用最少的车程参观每个房子。
现在,我已将其设置为我们尝试每一个目的地的排序,并确定用时最快的那个。但是有这么多 API 调用似乎效率低下,但我在 API 中看不到一种方法来做我想做的事。在 google 地图 API 中,我目前想要的是可能的吗?
您可以在路线 API 网络服务中使用 Waypoints,其中 returns 包括在中间位置经过或中途停留的路线。
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.
示例请求:
https://maps.googleapis.com/maps/api/directions/json?
origin=Adelaide,SA&destination=Adelaide,SA
&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA
&key=YOUR_API_KEY
请注意,使用航点优化的请求按 higher rate 收费。
如果您将使用 client-side 地图 JavaScript 路线服务。参考这个documentation and example.
希望对您有所帮助!