1
I次のコードを持っている:
<?php
$q = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=35.0078,-97.0929&destinations=45.2078,-97.0929&mode=driving&sensor=false";
$json = file_get_contents($q);
$details = json_decode($json, TRUE);
echo "<pre>"; print_r($details); echo "</pre>";
?>
結果は次のとおりです。
Array
(
[destination_addresses] => Array
(
[0] => 150th St, Summit, SD 57266, USA
)
[origin_addresses] => Array
(
[0] => 38591 Patterson Rd, Wanette, OK 74878, USA
)
[rows] => Array
(
[0] => Array
(
[elements] => Array
(
[0] => Array
(
[distance] => Array
(
[text] => 1,299 km
[value] => 1299343
)
[duration] => Array
(
[text] => 13 hours 26 mins
[value] => 48361
)
[status] => OK
)
)
)
)
[status] => OK
)
私は、$ jsonの距離のみ(1299キロ)から抽出する必要があります。 これを行う方法がわかりません。 何か助けていただければ幸いです。
これは非常によく似質問です思える:http://stackoverflow.com/questions/2703916/parsing-data-from-google-maps-api-v3-with-json-with-php – andresf