Search code examples
javascriptgoogle-mapsgoogle-maps-api-3google-distancematrix-api

Google Maps API Distance Matrix - Delay time to request (client-side) another 100 elements


I have a mini-map project that uses Distance Matrix Google Maps API to create a polyline (route) from start point to end point. I have many markers in my map and I have to connect them using Distance Matrix API to fetch the duration value.

The problem is the total requests of the Distance Matrix API are more than 100 elements, exactly 400 elements. I know that Google Maps API limit only to 100 elements per client-side request. According to the documentation,

While you are no longer limited to a maximum number of elements per day (EPD), the following usage limits are still in place for the Distance Matrix API:

Maximum of 25 origins or 25 destinations per request. Maximum 100 elements per server-side request. Maximum 100 elements per client-side request. 1000 elements per second (EPS), calculated as the sum of client-side and server-side queries.

So, I decide to divide the 400 elements into 4 requests (100 elements each). However, the documentation doesn't state how long should I wait to request another 100 elements.

Does anyone know?

Thank you.


Solution

  • Google's documentation does say how long you should wait here:

    Note: The rate limit is applied per user session, regardless of how many users share the same project. When you first load the API, you are allocated an initial quota of elements. Once you use this quota, the API enforces rate limits on additional requests on a per-second basis. If too many requests are made within a certain time period, the API returns an OVER_QUERY_LIMIT response code.

    So you'll need to wait at least 1 second before you make another request to the Distance Matrix client-side service.

    Hope this helps!