将地址转换为纬度/经度(使用php)

时间:2012-05-01 15:42:03

标签: php json web-services maps

我想用PHP解析此URL以获取特定地址的纬度(2 + bis + avenue + Foch75116 + Paris + FR):

我使用谷歌地图网络服务:http://maps.googleapis.com/maps/api/geocode/json?address=2+bis+avenue+Foch75116+Paris+FR&sensor=false

// Get the JSON 
$url='http://maps.googleapis.com/maps/api/geocode/json?address=2+bis+avenue+Foch75116+Paris+FR&sensor=false';
$source = file_get_contents($url);
$obj = json_decode($source);
var_dump($obj);

它不起作用。我有这个错误:

OVER_QUERY_LIMIT

所以我在网上搜索,我发现使用谷歌地图api有限制(2次查询之间最少1秒,每天最多2500次查询)

您知道如何将地址转换为 - >纬度/经度???

1 个答案:

答案 0 :(得分:8)

您正在错误地访问results

// Get the JSON 
$url='http://maps.googleapis.com/maps/api/geocode/json?address=2+bis+avenue+Foch75116+Paris+FR&sensor=false';
$source = file_get_contents($url);
$obj = json_decode($source);
$LATITUDE = $obj->results[0]->geometry->location->lat;
echo $LATITUDE;