[GIS] Google Maps Distance Matrix API – Queries per second

distancedistance matrixgoogle mapsgoogle-maps-api

I'm pretty familiar with Google's Distance Matrix API, but I'm unsure about one aspect of the Usage Limitations. The documentation states that you have access to 100 elements per query (element = origin * destination). So one could calculate up the distance of 10 origins and 10 destinations in one request, I understand this.

Where I'm stuck is where Google mentions that developers can request 100 elements per 10 seconds. What exactly does this mean? Is it saying that if I were to make a request of 10 origins & 10 destinations (100 elements), it would take 10 seconds to compute this?

Best Answer

Google limitations are:

100 elements per second, calculated as the sum of client-side and server-side queries.

If you request 100 elements or less (10 origins * 10 destinations for example), it will return the results in the time it takes to read your request, process it, and send back the results (probably less than a second).

Now, if you do other requests that bring the total above 100 elements within that one second interval, the API will return a status code OVER_QUERY_LIMIT (See: Top-level Status Codes). You will have to wait until this time interval elapses to do another request.

What you can do is measure how much time has elapsed between sending the request and receiving the result and wait the remaining time before sending a new request. Or redo the request a second later if you receive a response with the aforementioned status code.

EDIT: I know it is an old question but it might be useful for anyone stumbling upon this question.