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

问题描述 投票:1回答:1

我想用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个查询)

你知道怎样把地址转换成 - >纬度/经度???

php json web-services maps
1个回答
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;
© www.soinside.com 2019 - 2024. All rights reserved.