Reputation: 71
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";
}
Upvotes: 5
Views: 9663
Reputation: 101
Certain atypical or malformed address strings still throw this error.
As of this posting, certain address strings beginning with the hash # character result in an OVER_QUERY_LIMIT status response.
If you know you are under API call limits and usages, especially if you have a billed account with Google, I would look for unusual characters - particularly beginning the address string.
In most cases in which an apartment/unit number makes it into address data, removing the offending substring won't affect the position much.
Upvotes: 0
Reputation: 3322
The Geocoding has a daily limit of 2,500 but it is also throttled. So, as others have suggested, write in your PHP code sleep(1) statements about once every 10 records. You may also want to write a Queue Module/Process to control the requests. Cache the result into an Address Cache Module, or some other cache type.
Also, have you considered other domains/users on your IP Address? SugarCRM's SugarOnDemand has this issue. Too many users, sharing the same IP Address, trying to geocode addresses around the same time can cause the dreaded OVER_QUERY_LIMIT issue.
Be patient. If the above doesn't work. Get a laptop installed with a WAMP Server, and then go around to your local WIFI enabled coffee shops. They typically have different IP Addresses, so you'll be able to geocode 2500*5 each day. It's a pain, but it works.
If you really want to be creative, write a Proxy Script (PHP) to bounce the CURL request off of a different IP address (some other domain). Google's Geocoding API will think the request is coming from the Proxy Script's IP Address.
Upvotes: 1
Reputation: 1396
$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);
Upvotes: 0
Reputation: 180176
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).
Upvotes: 3