在我的当前项目中,这是一个交付系统,我有一个可用的交付司机列表,显示在订单页面上。但我需要显示每个交付员距离客户地址的距离。该距离应显示在每个司机姓名旁边。有人知道我该如何处理吗?
Documentation: https://developers.google.com/maps/documentation/directions/
例如: 从波士顿到康科德,途经查尔斯敦和列克星敦(JSON) http://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA&sensor=false 从波士顿到康科德,途经查尔斯敦和列克星敦(XML) http://maps.googleapis.com/maps/api/directions/xml?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA&sensor=false 请注意使用限制。$addressFrom = 'Insert from address';
$addressTo = 'Insert to address';
$distance = getDistance($addressFrom, $addressTo, "K");
echo $distance;
$origin =urlencode('Optus Sydney International Airport, Airport Drive, Mascot NSW 2020, Australia');
$destination = urlencode('Sydney NSW, Australia');
$url = "https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=$origin&destinations=$destination&key=your_key";
$data = @file_get_contents($url);
$data = json_decode($data,true);
echo $data['rows'][0]['elements'][0]['duration']['value'];