【发布时间】:2017-01-31 19:53:00
【问题描述】:
我之前有一个 Google 地理编码脚本,用于使用数据库中的本地地址提取经度和纬度。
在过去 6 个月中,我更换了主机,显然 Google 已经实施了新的正向地理编码器。现在它只是从 xml 脚本调用返回 url not loading 错误。
我已尽一切努力让我的代码正常工作。即使来自其他网站的示例编码也无法在我的服务器上运行。我错过了什么?是否有可能是服务器端设置阻止它正常执行?
尝试 #1:
$request_url = "http://maps.googleapis.com/maps/api/geocode/xml?new_forward_geocoder=true&address=1600+Amphitheatre+Parkway,+Mountain+View,+CA";
echo $request_url;
$xml = simplexml_load_file($request_url) or die("url not loading");
$status = $xml->status;
return $status;
仅返回未加载的 url。我尝试过使用和不使用 new_forwad_geocoder。我也尝试过使用和不使用 https。
如果您只是将 $request_url 字符串复制并粘贴到浏览器,它会返回正确的结果。
也试过这个只是为了看看我是否可以得到一个文件来返回。尝试 2:
$request_url = "http://maps.googleapis.com/maps/api/geocode/json?new_forward_geocoder=true&address=1600+Amphitheatre+Parkway,+Mountain+View,+CA";//&sensor=true
echo $request_url."<br>";
$tmp = file_get_contents($request_url);
echo $tmp;
知道什么可能导致连接失败吗?
【问题讨论】:
标签: php xml geocode google-geocoding-api