I would like to use the google directions API to develop route planning software for a company that handles snowplows in the winter and landscaping in the summer. One of the customers requirements is that he be able to calculate routes with at least 30 ( preferably more ) waypoints. According to the documentation (quoted below) even Google Maps API for Work customers are limited to just 23 waypoints per request.
Use of the Google Directions API is subject to a query limit of 2,500 directions requests per day. Individual directions requests may contain up to 8 intermediate waypoints in the request. Google Maps API for Work customers may query up to 100,000 directions requests per day, with up to 23 waypoints allowed in each request.
Is anyone aware of a workaround -- any way at all -- to get around this?
Also -- might it be possible to use a workaround for the free API? I hear the premier accounts are quite expensive.
Thanks!! Marc
There is a easy around this solution.
Keep the waypoints in array based on the distance threshold value and keep adding them. Once you reach the limit of 8 values in the array, assign the 1st position(Origin) of the waypoint array to a new waypoint array .... Assign the last waypoint to the new waypoint as the 2nd element... now replace the old waypoint array with this new one and continue.
Watever you do the waypoints will never cross more than 8 values and it will keep track of the route taken to map it out(Unless the journey is way too long)
The code below in C# calculates how many calls you will make Google Directions API and how many waypoints on each iteration. You can modify the Modmin to change the minimum waypoints that you want on your last iteration.
For example if you have totalWaypoints.Count = 97:
97 Mod 23 = 5, in this case i want a Modmin greater than 5, so i will calculate again with a lower waypointsByIteration;
97 Mod 22 = 9, (9 > Modmin) , OK;
iterations = ((97 - (97 % 22)) / (22)) + 1 = 5;
On the last iteration waypointsByIteration will be the residue.
Here is an hack to use more than 8 waypoints.Please checkout my solution for that.
Drawing roadmap with more than 8 waypoints using Google directions API
With following code you can use as many waypoints as you need and you will never get error MAX_WAYPOINTS_EXCEEDED. Do not forget to replace "YOUR_API_KEY" to your API KEY or remove &key=YOUR_API_KEY from google API URL and set variable "max" to 8 (max = 25 when using API KEY, max = 8 when not using API KEY).
fiddle with show/hide line buttons
You are correct the premier pricing is rather expensive starting at $10,000, last time I spoke with a google rep on the phone.
I found a workaround that I put into place to in a way bypasss the 8 waypoints limitation. I was able to make it work.
I did this by receiving my waypoints and breaking them up into different routes but drawing them together as the same route.
Example being if there were 30 waypoints needed I would draw 4 lines, but with the same color etc. So, basically you cut the waypoints into different routes calling the directions renderer each time as if it was a different route. The key is after the first route that the next route has to start with the last waypoint of the previous route (this makes sure that the route lines are connected to each other)
It works but you need to write a lot more code than what you would if you had a premier account, and you are calling for directions a lot more in this instance.
I have searched and thought about other ways to do this without having a premier account and have failed.
Although, I when speaking with google they did say that they intended on creating a tiered structure of payment for customers with different wants/needs. For instance, if a customer just needed more waypts and not a bunch more direction requests.
Hope this helps, as it worked for me in a practice application.