简体   繁体   中英

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 ?

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. $0.50 USD / 1,000 additional requests, up to 100,000 daily, if billing is enabled.

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.

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). I am currently requesting every single route with AsyncTasks and it is working fine, but it costs too much requests.

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.

Here is example of request that use alternatives parameter

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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