Google地图地理编码API只能通过浏览器运行 [英] Google Maps Geocode API only works via browser

查看:73
本文介绍了Google地图地理编码API只能通过浏览器运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我使用的网址:



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

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



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

p>

  $ 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
}

我做错了什么?



谢谢!

解决方案

在邮政编码数字之后放置一个空格,在我的情况下,在9462和AA之间,可以使用 file_get_contents

结论:通过浏览器,您可以在数字和字符之间进行带有或没有空格或+的API调用,而在PHP中,您需要使用空格或+来分隔这些API。



最终到达网址为:



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

I try to retrieve the latitude and longitude data by postalcode/zipcode.

This is the URL that I'm using:

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

The url returns JSON data (including latitude/longitude values) once I open it via the browser.

But when I call the exact same URL via the PHP file_get_contents method, it returns 'ZERO_RESULTS'.

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

echo $url; 
echo $geocode;

This prints the following result:

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

Geocode:

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

What am I doing wrong?

Thank you!

解决方案

Putting a space after the postalcode digits, in my case between 9462 and AA, works with file_get_contents.

Conclusion: via the browser you can do an API call with or without a space or '+' between the digits and characters, and in PHP you need to seperate those with a space or '+'.

The final URL became:

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

这篇关于Google地图地理编码API只能通过浏览器运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆