I've written a script to send an address to Google Maps' API and receive back the Lat and Lng. However, I'm receiving error messages that I've exceeded Google's rate limit after 20 or so queries. Is there something I'm not considering?
I'd appreciate any help. I'm very new at using API's so better understanding why I'm hitting the rate limit would be very helpful.
After reading the addresses from a csv file named Location, below is my relevant code.
for row in locations:
address = 'XXX, New Haven, CT'
first = re.search('^(.*),',row[0])
address = re.sub('XXX',first.group(), address)
lat, lng = gmaps.address_to_latlng(address)
And my error message is below.
Traceback (most recent call last):
File "<input>", line 5, in <module>
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/googlemaps-1.
0.2-py2.7.egg/googlemaps.py", line 310, in address_to_latlng
return tuple(self.geocode(address)['Placemark'][0]['Point']['coordinates'][1
::-1])
File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/googlemaps-1.
0.2-py2.7.egg/googlemaps.py", line 262, in geocode
raise GoogleMapsError(status_code, url, response)
GoogleMapsError: Error 620: G_GEO_TOO_MANY_QUERIES
According to Google's API Usage and Billing page, there is a limit of 50 requests per second. If you exceed this amount, subsequent requests to the API will fail with the OVER_DAILY_LIMIT or OVER_QUERY_LIMIT status code and the geocoded data will not be returned.
While there is no maximum number of requests per day, the following usage limits are in place for the Maps JavaScript API: 30,000 requests per minute. 300 requests per minute per IP address. In the Google Cloud Console, this quota is referred to as Map loads per minute per user.
Enable billing account for your project. Select the project that contains the API you want to review. From the list of APIs on the Dashboard, click the name of the API. Near the top of the page, click Quotas or Usage and set the limit according to your usage.
Google also started to require all API calls to use a valid API key, which has to be linked to a Google Cloud Platform account. Small companies aren't likely to reach the new limit. But when the number of customers and everyday freight traffic grows, the price for Google Maps services grows significantly.
Each gmaps.address_to_latlng
call sends a request to the Google server, and you can only make a limited number of those.
Google's docs on usage limits:
Use of the Google Geocoding API is subject to a query limit of 2,500 geolocation requests per day. [...] Additionally, we enforce a request rate limit to prevent abuse of the service.
And the docs on G_GEO_TOO_MANY_QUERIES
:
The given key has gone over the requests limit in the 24 hour period or has submitted too many requests in too short a period of time. If you're sending multiple requests in parallel or in a tight loop, use a timer or pause in your code to make sure you don't send the requests too quickly.
So, do just what they tell you to do:
import time
# And then in the loop, pause:
time.sleep(1)
Adjust the „1“ to an appropriate number of seconds so you don't run out of allowed requests.
I have co me to realize that most peope (like me) omit the part in the google map api that talks about the 'request rate limit' which is different then the 'page per day limit'.
so the 'request rate limit ' is of 10 requests per seconds.
So based on that if you display a page with 20 static maps... and the end user has a fast internet connection (maybe you?)...
then those 20 requests to the google map API happen faster then in the lapse of 1 second...
so by this you break their ryle and they block the image display.
this is my conclusion after just now reading on it here and there
good luck
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With