我多次问过这个问题但没有答案,我想使用谷歌的matrixapi获取客户和50家商店之间的驾驶距离,其中我有客户的纬度和经度,以及每个商店的经纬度数组ID
array:57 [▼
0 => array:3 [▼
"id" => 695
"lat" => "2.9315257"
"long" => "101.7638137"
]
1 => array:3 [▼
"id" => 696
"lat" => "2.9660291"
"long" => "101.7499998"
]
2 => array:3 [▼
"id" => 700
"lat" => "2.937143099999999"
"long" => "101.7779784"
]
我使用了 url,但很难使用它 forloop 那么我如何传递数组并获取每个商店及其 id 的距离
$distance_data = file_get_contents(
'https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins='.$from_latlong.'&destinations='.$to_latlong.'&key='.$googleApi
);
$distance_arr = json_decode($distance_data);
$distance = $distance_arr->rows[0]->elements[0]->distance->text;
$duration = $distance_arr->rows[0]->elements[0]->duration->text;
$distance = preg_replace("/[^0-9.]/", "", $distance);
$duration = preg_replace("/[^0-9.]/", "", $duration);
$distance=$distance * 1.609344;
$distance=number_format($distance, 1, '.', '');
$duration=number_format($duration, 1, '.', '');
神不在的星期二