【发布时间】:2015-03-26 09:07:45
【问题描述】:
我有一个简单的函数,它使用来自 Google 的简单 XML 将地址字符串转换为经度和纬度。我偶尔会收到这个奇怪的警告错误:
警告: simplexml_load_file(http://maps.googleapis.com/maps/api/geocode/xml?address=&sensor=true): 无法打开流:HTTP 请求失败! HTTP/1.0 500 内部 第 193 行 /search_results.php 中的服务器错误
警告:simplexml_load_file():I/O 警告:无法加载外部 实体 “http://maps.googleapis.com/maps/api/geocode/xml?address=&sensor=true” 在 /search_results.php 第 193 行 url 未加载
有没有更好的方法来避免这个错误?
我的代码如下:
$geo_address = urlencode($address);
$request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$geo_address."&sensor=true";
$xml = simplexml_load_file($request_url) or die ("url not loading");
$status = $xml->status;
if ($status=="OK") {
$lat = $xml->result->geometry->location->lat;
$lon = $xml->result->geometry->location->lng;
}
【问题讨论】:
-
看来你的内部php文件
(search_results.php)有问题HTTP/1.0 500 Internal Server Error,你可以试试this out
标签: php xml google-maps google-maps-api-3