我一直在拼命尝试使用Google API制作飞行距离计算器。
我最接近的是使用在另一个SO问题(Distance from point A to B using Google Maps, PHP and MySQL)上发布的答案来获得道路距离,如下所示:
$from = "Więckowskiego 72, Łódź";
$to = "Gazowa 1, Łódź";
$from = urlencode($from);
$to = urlencode($to);
$data = file_get_contents("http://maps.googleapis.com/maps/api/distancematrix/json?origins=$from&destinations=$to&language=en-EN&sensor=false");
$data = json_decode($data);
$time = 0;
$distance = 0;
foreach($data->rows[0]->elements as $road) {
$time += $road->duration->value;
$distance += $road->distance->value;
}
echo "To: ".$data->destination_addresses[0];
echo "<br/>";
echo "From: ".$data->origin_addresses[0];
echo "<br/>";
echo "Time: ".$time." seconds";
echo "<br/>";
echo "Distance: ".$distance." meters";
输出:
To: Gazowa 1, 91-076 Łódź, Poland
From: Więckowskiego 72, Łódź, Poland
Time: 206 seconds
Distance: 1488 meters
是否有任何简单的方法可以让上面提供距离,因为乌鸦过得很快?