【问题标题】:php xml Google Geocoding Errorphp xml谷歌地理编码错误
【发布时间】:2012-09-06 14:51:33
【问题描述】:

如果我理解 google 错误 OVER_QUERY_LIMIT 正确,那是因为 IP 请求太多。 但是,如果我转到浏览器并加载以下链接: http://maps.googleapis.com/maps/api/geocode/xml?address=Paris&sensor=true

我可以看到 xml!

那是为什么呢?

我的代码有问题吗?

这里是:

    $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];
        }
    }

【问题讨论】:

    标签: php xml simplexml google-geocoder


    【解决方案1】:

    使用 curl 代替 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;
    

    或查看以下网址

    Warning while using file_get_contents for google api

    【讨论】:

    • 好的。几天后,我对“卷曲”有同样的问题。我收到此“OVER_QUERY_LIMIT”错误。但这没有任何意义,我对谷歌的请求并不多。每天最多 10 个。那又怎样..我该如何解决这个问题?
    猜你喜欢
    • 2021-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多