I'm talking specifically about the quota of type elements per minute per user. I set this value to 150. The documentation says number of elements is origins x destinations.
This is how I call the api:
const distanceMatrixService = new google.maps.DistanceMatrixService();
const request = {
origins: [locator.searchLocation.location],
destinations: locator.locations.map(function (x) {
return x.coords;
}),
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: units,
};
distanceMatrixService.getDistanceMatrix(request, distancesReceivedCallback);
I get a proper response having 1 origin and locator.locations
contains 3 destinations. As far as I add a 4th destination I receive an error response:
{
"destination_addresses" : [],
"error_message" : "Distance Matrix Service: You have exceeded your rate-limit for this API.",
"origin_addresses" : [],
"rows" : [],
"status" : "OVER_QUERY_LIMIT"
}
The other quotas are all set to a very high value so they should not be a problem.
Why am I exceeding the quota of 150 with 4 destinations but not with 3?
From the documentation my requests should count as 4 (1 x 4) elements. The only way the api works reliable is when I set this specific quota to unlimited which is not desireable for my use case.
Elements per minute seems to have been misunderstood. From what I can see, the OVER_QUERY_LIMIT
error appears because the quotas you have set is working as intended.
Let me explain how Elements Per Minute Work:
When setting up your quota using Elements Per Minute, you should divide it with 60 to get Elements Per Second. The result would be your maximum query "every" second. So when you have set your Elements Per Minute to 150, this means that your maximum Elements Per Second is at 2.5 Elements.
150 Elements per minute / 60 = 2.5 Elements per second
The API might be rounding up the 2.5 to 3 and that explains why you are not receiving an OVER_QUERY_LIMIT
error if you implement 3 elements (1 origin x 3 destinations) and receive it when you implement 4 elements (1 origin x 4 destinations) because, ofcourse, you are "OVER" the quota of elements per second that you have set.
I hope this answers your question. And please feel free to confirm it in the comments if this fixed your issue.