简体   繁体   English

使用Directions API通过一个请求获取多个路线

[英]Get multiple directions with one request with Directions API

This might sound weird, but is there a way to request multiple directions with only one call to the Directions API ? 这听起来可能很奇怪,但是有一种方法可以仅通过一次调用Directions API来请求多个路线?

I'm asking this because I need to calculate a lot of routes at the same time, and I recently saw this : 我问这个问题是因为我需要同时计算很多路线,而最近我看到了这一点:

Free up to 2,500 requests per day. 每天最多释放2,500个请求。 $0.50 USD / 1,000 additional requests, up to 100,000 daily, if billing is enabled. $ 0.50 USD / 1,000个额外请求,每天最多100,000个(如果启用了结算)。

2,500 requests per day seems to be ok, but as I said I need to calculate a LOT of routes at the same time (up to 50 I think), so 2,500 is way too small. 每天2,500个请求似乎还可以,但是正如我所说,我需要同时计算很多路线(我认为最多50条),因此2,500个太小了。

Here is why I need to calculate these routes: 这就是为什么我需要计算这些路线的原因:
I need to get multiple routes from multiple departures points but with the same arrival point (for example route from B to A, route from C to A etc), to find which route is faster (but I need to save all the routes). 我需要从多个出发点获得多个路线,但要使用相同的到达点(例如,从B到A的路线,从C到A的路线等),以找出哪条路线更快(但我需要保存所有路线)。 I am currently requesting every single route with AsyncTasks and it is working fine, but it costs too much requests. 我目前正在使用AsyncTasks请求每条路由,并且运行良好,但请求费用过多。

Please share if you have any idea on how I could limit the number of requests, and thank you in advance 如果您对我可以如何限制请求数量有任何想法,请分享,并在此先感谢您

You may try to use the parameter alternatives , if it is set to true, it specifies that the Directions service may provide more than one route alternative in the response. 您可以尝试使用参数alternatives ,如果将其设置为true,则它指定Directions服务可以在响应中提供多个路线选择。

Here is example of request that use alternatives parameter 这是使用Alternatives参数的请求示例

https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&alternatives=true&key=YOUR_API_KEY

Just take note that providing route alternatives may increase the response time from the server. 请注意,提供替代路线可能会增加服务器的响应时间。

For more information, you can check this SO questions: 有关更多信息,您可以检查以下SO问题:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM