How do I Geocode 20 addresses without receiving an OVER_QUERY_LIMIT response?
No, there is not really any other way : if you have many locations and want to display them on a map, the best solution is to :
- fetch the latitude+longitude, using the geocoder, when a location is created
- store those in your database, alongside the address
- and use those stored latitude+longitude when you want to display the map.
This is, of course, considering that you have a lot less creation/modification of locations than you have consultations of locations.
Yes, it means you'll have to do a bit more work when saving the locations -- but it also means :
- You'll be able to search by geographical coordinates
- i.e. "I want a list of points that are near where I'm now"
- Displaying the map will be a lot faster
- Even with more than 20 locations on it
- Oh, and, also (last but not least) : this will work ;-)
- You will less likely hit the limit of X geocoder calls in N seconds.
- And you will less likely hit the limit of Y geocoder calls per day.
Google Geocoding API OVER_QUERY_LIMIT issue
The Geocoding API has a queries per second (QPS) limit. You cannot send more than 50 QPS.
This limit is documented at
https://developers.google.com/maps/documentation/geocoding/usage-and-billing#other-usage-limits
While you are no longer limited to a maximum number of requests per day (QPD), the following usage limits are still in place for the Geocoding API:
- 50 requests per second (QPS), calculated as the sum of client-side and server-side queries.
In order to solve your issue I would suggest using the Python client library for Google Maps API Web Services:
https://github.com/googlemaps/google-maps-services-python
This library controls QPS internally, so your requests will be queued properly.
I hope this helps!
Geocode OVER QUERY LIMIT workaround
First a note about Google's Terms of Service
It's easy to not think about stuff like this, but it does matter sometimes. Unless you want to join this group from earlier today which for some reason had their service disabled, make sure that you are showing a map to the user as you geocode these addresses. The TOS also prohibit bulk geocoding and storing the results for anything other than performance caching.
Not accusing! Just bringing to attention.
The programmer answer:
setTimeout
's callback and geocode
are both asynchronous functions. Right now with your code, while the response is still coming back from the API, you're starting your 1-second timer which also runs asynchronously while your loop continues to iterate immediately with no delay. After one second, the no-op is called once then discarded. This happens each time the loop is run.
So you're shooting off a thousand API requests at once. Then about 1 second later (give or take a few milliseconds), 1,000 no-ops will run.
Your calls to g.geocode
need to be inside the callback function of setTimeout
, and then the end of the callback function will need to set another timeout with itself inside it, until you are done. No more no-op.
If you want to more correctly "work around" the OVER_QUERY_LIMIT
errors and other TOS restrictions (like geocoding en masse), you'll want to consider a commercial service that doesn't have such limits, something like LiveAddress (disclosure: I work at SmartyStreets).
what is the best geocode to get long and lot for a street address?
Geocode the addresses off-line and "cache" the results (for less than 30 days to comply with the terms of service), use the coordinates to display your markers.
More details: Geocoding Strategies article in the Google Maps Documentation.
GMap Geocoding: Over query limit
Google limits the number of geocoding requests per second. You can either wait or cache the results somewhere in your own database.
See this related question.
Related Topics
How to Write a Script to Edit a JSON File
JavaScript Date.Utc() Function Is Off by a Month
Sort an Array of Object by a Property (With Custom Order, Not Alphabetically)
Encrypting Data with Ruby Decrypting with Node
How to Get the Nth Occurrence in a String
Ruby on Rails 4 JavaScript Not Executed
How to Count the Number of Occurrences of Each Item in an Array
How to Search in Array of Object in Mongodb
Capture Browser Console Logs with Capybara
Preloader Wont Ignore Websocket - Pace Js
Template Language That Works on Both Server and Client
What Does It Mean That JavaScript Is a Prototype Based Language
Sort JavaScript Array by Two Numeric Fields
How to Include Js.Erb File in View Folder
JavaScript with Embedded Ruby: How to Safely Assign a Ruby Value to a JavaScript Variable