Php 从google maps api获取响应时,simplexml_加载_文件解析器错误
这些错误已经困扰了我一天,我甚至不知道如何修复它。我有一个网站运行了一年多,没有任何问题。基本上,当我通过表单向数据库添加新记录时,它使用来自GoogleMapsAPI的地理代码获得xml纬度和经度响应,然后将记录插入数据库。但当我昨天尝试这样做时,它返回了错误 “警告:simplexml_load_file()[function.simplexml load file]:“MY-API-KEY”&address=411+Church+Street++%2C+Parramatta+NSW+2150%2C+Australia&sensor=false:1:解析器错误:第40行/MY-SITE-DIR/geoCode-1.php中的文档为空” 当我将url直接放入浏览器时,它会返回一个完美的xml,这意味着我的url实际上是好的。我进行了一整天的研究,找到了一些解决方案,以下内容最符合我的问题: 是添加用户代理。但对我来说不起作用 有人有什么建议吗?以下是我的相关代码:Php 从google maps api获取响应时,simplexml_加载_文件解析器错误,php,xml,google-maps-api-3,google-api,Php,Xml,Google Maps Api 3,Google Api,这些错误已经困扰了我一天,我甚至不知道如何修复它。我有一个网站运行了一年多,没有任何问题。基本上,当我通过表单向数据库添加新记录时,它使用来自GoogleMapsAPI的地理代码获得xml纬度和经度响应,然后将记录插入数据库。但当我昨天尝试这样做时,它返回了错误 “警告:simplexml_load_file()[function.simplexml load file]:“MY-API-KEY”&address=411+Church+Street++%2C+Parramatta+NSW+215
$xml = simplexml_load_file($request_url) or die("url not loading");
$status = $xml->Response->Status->code;
if (strcmp($status, "200") == 0) {
// Successful geocode
$geocode_pending = false;
$coordinates = $xml->Response->Placemark->Point->coordinates;
$coordinatesSplit = split(",", $coordinates);
// Format: Longitude, Latitude, Altitude
$lat = $coordinatesSplit[1];
$lng = $coordinatesSplit[0];
$query = sprintf("UPDATE orthodontist " .
" SET lat = '%s', lng = '%s' " .
" WHERE id = '%s' LIMIT 1;",
mysql_real_escape_string($lat),
mysql_real_escape_string($lng),
mysql_real_escape_string($id));
$update_result = mysql_query($query);
if (!$update_result) {
die("Invalid query: " . mysql_error());
}
}
API V2在几天前停止工作。我可以从你的代码看出,你使用的是API V2 您需要使用API v3 下面是一个用于v3的PHP代码示例 www.fcsoftware.co.uk/blog/?p=66