开发者

Hitting rate limit for google maps API, But don't know why

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 26开发者_Go百科2, in geocode
        raise GoogleMapsError(status_code, url, response)
    GoogleMapsError: Error 620: G_GEO_TOO_MANY_QUERIES


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜