Google API多维数组



我有点卡住了。为什么我没有在我的代码中提取纬度和经度?我看不出瑕疵。提前感谢!

$json  = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address=Boston');
$result = json_decode($json, true);
$glat = $result->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$glong = $result->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
print $glat.",".$glong;

你使用的结果作为一个对象,但它是一个数组,这里是固定的代码:

    $json  = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address=Boston');
    $result = json_decode($json, true);
    $glat = $result['results'][0]['geometry']['location']['lat'];
    $glong = $result['results'][0]['geometry']['location']['lng'];

相关内容

  • 没有找到相关文章

最新更新