Hitting `OVER_QUERY_LIMIT` error using the Google Elevation Service for any more than 2 requests
Asked Answered
C

2

8

Premise

I'm using the Google Elevation Service to get elevations of all nodes along a path, drawn onto a Leaflet map by a user. This allows me to generate an elevation chart. At the moment, if I make more than 2 requests (there is a limit of 512 locations per request), I always hit an OVER_QUERY_LIMIT.

Usage Policy

  • 2,500 free requests per day, calculated as the sum of client-side and server-side queries; enable billing to access higher daily quotas, billed at $0.50 USD / 1000 additional requests, up to 100,000 requests daily.
  • 512 locations per request.
  • 50 requests per second*, calculated as the sum of client-side and server-side queries combined.

From the Google Elevation Service Site

I know I'm not hitting the 2500 requests a day (can see in the developer console how many have been made). I also know that there are definitely 512 locations per request, which leaves the only quota to be hitting being the 50 requests per second.

Method

To deal with large volumes of nodes I am doing the following:

  1. Input list of nodes to function
  2. Take first chunk (512 locations) from list
  3. Make API call with that chunk
  4. Append returned elevations to an array
  5. Wait for 1 second
  6. Loop from 2 to 5 until list is depleted

Code in action: Codepen

If I make the waiting time massive in between each request (say 5 seconds), the requests are sent fine, but from what I can tell, I should be able to send 50 requests a second - so a list of 10,000 nodes should take 20 requests, and theoretically not even need a wait - but even with the wait its hitting the error.

Colophon answered 15/3, 2018 at 12:13 Comment(0)
C
1

There appears to be another limit: 1024 locations during a 5 second window. So 2 request of 512 locations each, 4 at 256, 8 at 128, etc, all work but then you have to wait 5 seconds for the next request. I think the 50 requests per second limit only kicks in if the total location count is 1024 or less.

Cyclosis answered 18/7, 2018 at 8:31 Comment(0)
A
3

First check answers from here

I am not sure but you can check with this and this leaflet plugin.

Google articles already documented same issues which you are facing currently. And given some solutions also

I checked your Codepen also.

Still if you have only Google elevation service option then you need to check with some logic like:

  • Try to replicate same code with different Google API key and merge results.
  • Check is it possible to import Google API script cdn in for loop where you use 5-6 different API keys.

Finally last option is Use a Google Maps APIs for Work license

Important: Please change or use demo Google API key which you used in codepen. Because anybody can use your key. or protect it from Google API console Under Accept requests from these HTTP referrers (websites), this is where you limit the key to your domain name.

Amorete answered 22/3, 2018 at 15:50 Comment(1)
Cheers for the pointers - there are certainly a few workarounds with the plugins mentioned, and the API key rotation etc. but I would like to get to the bottom of this, and work out why this code is hitting the quota limit, when as far as I can see - it should be well within the limits. Cheers all the sameColophon
C
1

There appears to be another limit: 1024 locations during a 5 second window. So 2 request of 512 locations each, 4 at 256, 8 at 128, etc, all work but then you have to wait 5 seconds for the next request. I think the 50 requests per second limit only kicks in if the total location count is 1024 or less.

Cyclosis answered 18/7, 2018 at 8:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.