Reputation: 135
I have a database with a list of locations and I have to get the route steps, drive distance and drive time for all combinations of locations in the database.
I have the latitude and longitude stored in the database for every location.
I'm using the google directions service api to get the information.
As long as the number of records was low, I could get the results from my code within a minute using threading.
However as the number of records increased, the number of records in combination increased exponentially (trust me, this is not the issue and the number of combinations have the potential to reach 100K), thereby causing an increase in the number of requests to be made to directions api and hence the time taken for retreival.
I understand since a large number of rest connections need to be made to the directions api, network latency plays in and the time taken to retrieve the results increases.
I googled and found that some of the maps api's (for instance waypoints in the directions service api) allow you to specify more than 1 value using the pipe operator ( | ).
I attempted to do the same and retrieve information for one source multiple destinations for every rest request however I get a NOT_FOUND status returned from the directions service.
Could someone please help me figure out how to get routes and the distance and time from the same origin but multiple destinations using the directions api.
Following is a sample url and the response I received (API_KEY was removed on purpose, cannot share that): https://maps.googleapis.com/maps/api/directions/json?key=API_KEY&origin=49.794150,-84.564514&destination=49.244978,-88.146057|49.173205,-84.756775
{
"geocoded_waypoints" : [
{},
{
"geocoder_status" : "ZERO_RESULTS"
}
],
"routes" : [],
"status" : "NOT_FOUND"
}
Upvotes: 4
Views: 10093
Reputation: 32148
Directions API doesn't support multiple origins or destinations. You can specify one origin, one destination and up to 23 waypoints.
https://developers.google.com/maps/documentation/directions/intro#Waypoints
The request with waypoints looks like:
If you would like to test your routes and see the visual representation, you can use Directions calculator:
Hope it helps!
Upvotes: 7