请求谷歌地图地理定位API
我想通过使用PHP 5请求Web服务 - Google地理定位API。我有使用PHP进行XML解析的经验,但是这个使用JSON格式来制作请求。我不知道如何提出请求!我认为接收请求与XML解析类似!请求谷歌地图地理定位API
https://developers.google.com/maps/documentation/business/geolocation/
如果你有一个商业帐户,通过你的链接,谷歌供应帮助的建议。如果您没有商业账户,您将需要使用提供xml结果的使用This API。 即
http://maps.googleapis.com/maps/api/geocode/xml?address=anywhere&sensor=true
或
sensor=false
试试这个(结果以JSON格式):
public function getGeoPosition($address){
$url = "http://maps.google.com/maps/api/geocode/json?sensor=false" .
"&address=" . urlencode($address);
$json = file_get_contents($url);
$data = json_decode($json, TRUE);
if($data['status']=="OK"){
return $data['results'];
}
}
print_r(getGeoPosition('chicago,il'));
任何想法,为什么这个要求只会在部分时间内工作?它对我来说已经超时了,而且实际上告诉我它已经超时了。 – mcbeav 2014-08-20 01:48:36
您可以尝试新的网址: https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA 另请参阅此处的使用限制: https://developers.google.com/maps/documentation/geocoding/#Limits – 2014-08-20 16:52:48
你不解析JSON。你'json_decode()'无论你得到什么,它给你一个原生的PHP数组/对象,然后你从那里开始。 – 2013-04-04 14:55:06