php - 没有路况的谷歌地图方向请求

标签 php json maps google-directions-api

我必须编写一个程序,告诉我两点之间的最短路线。流量不应该考虑。

我的请求是这样的。

'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/

相关文章:

php - Laravel - Sentinel 用户与 eloquent 用户不同

javascript - 第一次单击单选按钮后无法触发更改事件

php - Json key 缺少 google photos api 中的刷新 token 字段

javascript - 使用node.js解析json数组

java - GET 不显示在 java 动态 Web 项目中实现的 Posted 对象

kotlin - 合并具有相似外部键的嵌套映射,保留两个内部映射的键值对

java - 在 Google map 上绘制自定义 map 图 block 图像 (.pngs) - Android

php - FOSRestBundle 序列化程序错误

json - 在 Angular 中将 JSON 导出为 CSV

angularjs - Google map 地点自动完成 - 未捕获类型错误 : Cannot read property 'getPlace' of undefined