Reputation: 78
I hope you can help. Actually I´m trying to prevent the Google Maps-Api-Error "OVER_QUERY_LIMIT". I want to solve it with PHP instead of using Javascript and playing around with Timeouts etc. For this I have replaced this line:
geocoder.geocode( {'address': address}, function(results, status) {
in my script with this one:
var url_addr = encodeURIComponent(address);
$.getJSON('geocode.php?addr='+url_addr, function(data) {
var results = data.results,
status = data.status;
Additionally I have an PHP-Script for getting the geocode-coordinates:
$params = "address=" . urlencode($_GET{'addr'});
$url = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&' . $params;
$json = file_get_contents($url);
$status = json_decode($json)->status;
// check for over_query_limit status
while ($status=="OVER_QUERY_LIMIT") {
sleep(0.2); // seconds
$json = file_get_contents($url);
$status = json_decode($json)->status;
}
header('application/json');
echo $json;
After running this I can see the called PHP-script in the debugger-console with the attached geocode-coordinates on the URL like /geocode.php?addr=432345...
Next in my JS-Script I want to check if the google.maps.GeocoderStatus is OK. So I call:
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
console.log("Everything OK");
}
else {
console.log("Geocode is not OK");
}
But nothing happens. It seems that the status doesn´t arrive at the if-else. I played a bit around and tried to find out something with "Firebug", but I don´t find the answer.
Do you have any ideas?
Thank you and regards, Stefan
Upvotes: 1
Views: 767
Reputation: 434
I recommend you to use your Google API Key in your PHP.
https://maps.google.com/maps/api/geocode/json?address=".$params."&key=".$key."&sensor=false
$key = your Google API Key
It will help you prevent the OVER_QUERY_LIMIT errors.
Upvotes: 1