0

if i understand the google error OVER_QUERY_LIMIT right, than it comes because of too many ip-requests. BUT if I go to the browser and load the following link: http://maps.googleapis.com/maps/api/geocode/xml?address=Paris&sensor=true

I can see the xml!

So why is that?

Do I have a problem in my code?

Here it is:

    $the_map = htmlspecialchars($_POST['map'], ENT_QUOTES);

    error_reporting(0);
    $map_query = file_get_contents('http://maps.google.com/maps/api/geocode/xml?address='.rawurlencode($the_map).'&sensor=false');
    error_reporting(1);

    if ($map_query){
        $geo_code = simplexml_load_string(utf8_encode($map_query));

        if ($geo_code){
            $map_lat = $geo_code->xpath("/GeocodeResponse/result/geometry/location/lat");
            $map_lng = $geo_code->xpath("/GeocodeResponse/result/geometry/location/lng");
            $map_lat = $map_lat[0][0];
            $map_lng = $map_lng[0][0];
        }
    }

1 Answer 1

1

Use curl instead of file_get_contents:

$address = "India+Panchkula";
$url = "http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false&region=India";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response);
echo $lat = $response_a->results[0]->geometry->location->lat;
echo "<br />";
echo $long = $response_a->results[0]->geometry->location->lng;

Or See the below URL

Warning while using file_get_contents for google api

Sign up to request clarification or add additional context in comments.

1 Comment

ok. after a few days i have the same problem with "curl". I get this "OVER_QUERY_LIMIT" Error. But it makes no sense, i don't have that many requests to google. max 10 per day. so what .. how can i solve the problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.