Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 779
Ed Prince Avatar asked Mar 15 '18 12:03

Ed Prince


2 Answers

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.

like image 136
Rahul Mahadik Avatar answered Nov 13 '22 20:11

Rahul Mahadik


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.

like image 1
jerrysch Avatar answered Nov 13 '22 19:11

jerrysch