首页 文章

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

提问于
浏览
1

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

我使用谷歌 Map 网络服务: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

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

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

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;
    

相关问题