Google Geocoding API Error: OVER QUERY LIMIT

maximeismer picture maximeismer · Jul 24, 2013 · Viewed 9.3k times · Source

I am currently using the Google Geocoding API and using it very sparingly. The limit is 2500 queries per day and I am probably in the range of 20-50 at most. Then every so often in the past week I will get an OVER_QUERY_LIMIT error. I am only processing 1 address at a time and there are no loops or anything. It only geocodes once and send the lat/lng to a database and after that it will only be reference from the database. Can anyone tell me why I'm getting this error?

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

This worked flawlessly for over a month of testing until about a week ago.

I have a few pages that do the same thing but are only referenced at different times for different purposes. Here is all the code for the 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's 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";
}

Answer

ceejayoz picture ceejayoz · Jul 24, 2013

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