首页 文章

Google Maps Geocode API仅适用于浏览器

提问于
浏览
1

我尝试通过邮政编码/邮政编码检索纬度和经度数据 .

这是我正在使用的URL:

http://maps.google.com/maps/api/geocode/json?address=9462AA

一旦我通过浏览器打开它,url就会返回JSON数据(包括纬度/经度值) .

但是当我通过PHP file_get_contents 方法调用完全相同的URL时,它返回'ZERO_RESULTS' .

$url = 'http://maps.google.com/maps/api/geocode/json?address=9462AA';
$geocode = file_get_contents($url);

echo $url; 
echo $geocode;

这将打印以下结果:

网址:http://maps.google.com/maps/api/geocode/json?address=9462AA

地理编码:

{
   "results" : [],
   "status" : "ZERO_RESULTS"
}

我究竟做错了什么?

谢谢!

1 回答

  • 0

    在邮政编码数字之后加一个空格,在我的情况下在9462和AA之间,与 file_get_contents 一起使用 .

    结论:通过浏览器,您可以使用或不使用空格或数字和字符之间的''进行API调用,而在PHP中,您需要使用空格或''分隔 .

    最终的网址变为:

    http://maps.google.com/maps/api/geocode/json?address=9462+AA

相关问题