谷歌API地理编码和cUrl,"字符串无法解析为XML"

时间:2014-03-13 01:24:20

标签: php geocode

        $url="https://maps.googleapis.com/maps/api/geocode/xml? address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false&key=..."
        $ch = curl_init($url);
        $response = curl_exec($ch);
        curl_close($ch);
    $response = new SimpleXMLElement($response);
        $latitude = $response->result->geometry->location->lat;
        echo $latitude;

返回致命错误:未捕获的异常'Exception',消息'String无法解析为XML'

我尝试将oe = utf-8添加到网址但没有改进,当我在浏览器中加载网站时,我可以看到结果与标题一样好“这个XML文件似乎没有关联的任何样式信息文件树如下所示。“我如何重新格式化,以便SimpleXMLElement可以读取它?

更新:file_get_contents($ url);工作正常我已经尝试过,可以使用SimpleXMLElement(),我也尝试添加不同的curl_setopts,但他们仍然不返回XML文件。如果有人能帮我解决这个问题,我仍然会尝试使用curl。

curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);

由于

0 个答案:

没有答案
相关问题