2016-08-29 9 views
0

私はちょっと固まっています。なぜ私のコードで緯度と経度を抜かないのですか? 私は欠陥を見ることができません。前もって感謝します!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; 
+0

$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']; 
第二引数( 'true'を)' json_decode() '-methodにはオブジェクトの代わりに連想配列を返すよう指示します。以下の@ Templarの答えを見てください...将来の参考のために、オブジェクトプロパティの中に中括弧を入れる必要はありません。 '$ result-> results'は' $ result - > {'results'} 'と同じものです。 –

答えて

1

オブジェクトとして結果を使用しているが、それは、ここでは固定コード配列である。