Google Geocoding API Error: QUERY Limit Exceeded

I currently use the Google Geocoding API and use it very sparingly. The limit is 2500 requests per day, and I probably no more than 20-50. Then every time last week I get an OVER_QUERY_LIMIT error. I only process 1 address at a time and there are no loops or anything else. It only geocodes once and sends lat / lng to the database, and after that it will only be a link from the database. Can someone tell me why I am getting this error?

$request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$siteAddress."&sensor=true"; 

This worked flawlessly for a month of testing up to a week ago.

I have several pages that do the same thing, but are only mentioned at different times for different purposes. Here is all the code for geocoding.

  $request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$siteAddress."&sensor=true"; // the request URL you'll send to google to get back your XML feed $xml = simplexml_load_file($request_url) or die("url not loading");// XML request $status = $xml->status;// GET the request status as google api can return several responses if ($status=="OK") { //request returned completed time to get lat / lang for storage $lat = $xml->result->geometry->location->lat; $long = $xml->result->geometry->location->lng; echo "latitude:$lat, longitude:$long <br>"; echo "$lat, $long <br>"; //spit out results or you can store them in a DB if you wish } if ($status=="ZERO_RESULTS") { //indicates that the geocode was successful but returned no results. This may occur if the geocode was passed a non-existent address or a latlng in a remote location. $errorcode = "ZERO RESULTS"; echo "ZERO RESULTS"; } if ($status=="OVER_QUERY_LIMIT") { //indicates that you are over your quota of geocode requests against the google api $errorcode = "Over Query Limit"; echo "Over Query Limit"; } if ($status=="REQUEST_DENIED") { //indicates that your request was denied, generally because of lack of a sensor parameter. $errorcode = "Request Denied"; echo "Request Denied"; } if ($status=="INVALID_REQUEST") { //generally indicates that the query (address or latlng) is missing. $errorcode = "Invalid Request"; echo "Invalid Request"; } 
+4
source share
3 answers

The Google Geocoding API has a daily limit, but also limits the speed at which you can make requests. Put a sleep(1) call between geocode calls, and you'll probably be fine (if not, try increasing it by a couple of seconds).

+2
source

Geocoding has a daily limit of 2500, but it is also throttled. So, as others suggested, write in your PHP instructions sleep sleep (1) approximately every 10 entries. You can also write a queue module / process for managing requests. Load the result into the address cache module or some other type of cache.

Also, have you viewed other domains / users on your IP address? SugarCRM SugarOnDemand has this problem. Too many users sharing the same IP address while trying to geocode addresses at the same time can cause the dangerous OVER_QUERY_LIMIT problem.

Be patient. If the above does not work. Get a laptop installed on the WAMP server, and then go to your local WIFI-enabled cafeteria. As a rule, they have different IP addresses, so you can geocode 2500 * 5 every day. It is a pain, but it works.

If you really want to be creative, write Proxy Script (PHP) to drop the CURL request from a different IP address (some other domain). The Google Geocoding API will assume that the request comes from the IP address of Proxy Script.

+1
source
  $ output = json_decode (stripslashes (file_get_contents ('http://maps.googleapis.com/maps/api/geocode/json?latlng='.$data [' lat '].', '. $ data [' lon ' ]. '& sensor = false & language = ru')));
 print $ output-> results [0] -> formatted_address
 sleep (2); 
0
source

Source: https://habr.com/ru/post/1493287/


All Articles