1
我有以下代碼:
<?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 2012-04-13 23:17:40