我必须编写一个程序,告诉我两点之间的最短路线。流量不应该考虑。
我的请求是这样的。
'http://maps.googleapis.com/maps/api/directions/json?origin='.$from.'&destination='.$to.'&alternatives=true&sensor=false'
那我就这样走最短的路
$data = json_decode(file_get_contents($url))->routes;
usort($data,create_function('$a,$b','return intval($a->legs[0]->distance->value) - intval($b->legs[0]->distance->value);'));
return floatval($data[0]->legs[0]->distance->text);
但这个结果取决于实际流量。 如何发送忽略实际流量的请求?
最佳答案
您是否尝试过使用 Distance Matrix Service ?
考虑到 API 文档,这应该是您要查找的内容:
Google's Distance Matrix service computes travel distance and journey duration between multiple origins and destinations using a given mode of travel.
This service does not return detailed route information.
使用此服务时应忽略交通状况。
关于php - 没有路况的谷歌地图方向请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35218909/