我尝试通过postalcode/zipcode检索纬度和经度数据。
这是我使用的URL:
http://maps.google.com/maps/api/geocode/json?address=9462AAurl返回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;
打印如下结果:
的URL: http://maps.google.com/maps/api/geocode/json?address=9462AA
项目点:
{
"results" : [],
"status" : "ZERO_RESULTS"
}
我做错了什么?
谢谢!
在邮政编码数字后面加一个空格,在我的例子中,在9462和AA之间,适用于file_get_contents
。
结论:通过浏览器,你可以在数字和字符之间使用或不使用空格或'+'来进行API调用,而在PHP中,你需要使用空格或'+'来分隔它们。
最终URL变成:
http://maps.google.com/maps/api/geocode/json?address=9462 + AA