javascript - 使用 Google map 考虑交通情况的具有多个路径点的路线规划器

标签 javascript google-maps ionic-framework google-maps-api-3

希望这个问题有意义。 我正在与一名程序员合作开发一个 Ionic 应用程序,该应用程序使用 Google Maps API 允许用户创建具有多个路径点的自定义路线。

这是一个路线规划应用程序。

有一个“优化我的路线”按钮,用于检查您输入航路点的顺序是否是在旅行期间节省时间的最佳方式。如果没有,它会重新安排您的路线,以确保您不会浪费时间。

我要求我的程序员确保在您按下“优化我的路线”按钮时考虑流量数据,但他说根据此 API 文档这是不可能做到的:

https://developers.google.com/maps/documentation/directions/intro#DirectionsAdvanced

他表示,只能根据正常出行时间来优化路线,而无法获取路况信息。

我信任他,但我很难相信使用 Google Maps API 无法在考虑交通信息的情况下优化路线。

有什么想法或例子可以帮助我吗?

非常感谢!

编辑:

文档中似乎不可能实现的部分是:

Traffic information is used when all of the following apply :
-...
-...
-The request does not include stopover waypoints. If the request includes waypoints, prefix each waypoint with via: to influence the route but avoid stopovers.

该应用程序使用中途停留航点来允许用户创建路线。有什么解决方法吗? “Via”似乎是一个不错的选择,但不允许用户告诉应用程序他在特定事件中停留了多长时间。

谢谢

最佳答案

我相信您的开发人员是完全正确的。无法在 Directions API 中考虑当前的交通状况来优化路线。如果我们检查文档,我们可以看到以下关于优化的声明

By default, the Directions service calculates a route through the provided waypoints in their given order. Optionally, you may pass optimize:true as the first argument within the waypoints parameter to allow the Directions service to optimize the provided route by rearranging the waypoints in a more efficient order. (This optimization is an application of the traveling salesperson problem.) Travel time is the primary factor which is optimized, but other factors such as distance, number of turns and many more may be taken into account when deciding which route is the most efficient. All waypoints must be stopovers for the Directions service to optimize their route.

来源:https://developers.google.com/maps/documentation/directions/intro#OptimizeWaypoints

另一方面,如果您检查文档的流量部分中的持续时间,它会说明

Traffic information is used when all of the following apply (these are the conditions required to receive the duration_in_traffic field in the Directions response):

  • The travel mode parameter is driving, or is not specified (driving is the default travel mode).
  • The request includes a valid departure_time parameter. The departure_time can be set to the current time or some time in the future. It cannot be in the past.
  • The request does not include stopover waypoints. If the request includes waypoints, prefix each waypoint with via: to influence the route but avoid stopovers.

来源:https://developers.google.com/maps/documentation/directions/intro#DirectionsAdvanced

注意用粗体标记的句子。遗憾的是,交通信息不允许进行路线优化所需的中途停留。

关于javascript - 使用 Google map 考虑交通情况的具有多个路径点的路线规划器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51690260/

相关文章:

javascript - "_"是否有创建键 => 值对象的快捷方式?

javascript - JavaScript 局部变量是否应该间歇性地使用来提高性能?

Android SHA1 版本 keystore 不适用于 Google map

angular - ionic 相机插件可以在 Android 应用程序中工作,但不能在移动浏览器中工作?

javascript - 有没有一种添加新框并使用 javascript 重绘 Canvas 的好方法?

javascript - if else 变量作用域在 js 的 else 中显示未定义

javascript - 如何在动态生成的 input-angularjs 中显示动态 Json 数据?

ionic-framework - 如何让iOS应用程序全屏显示

javascript - 在 Google map 上使用 KML 叠加层进行用户输入搜索

Android 假 GPS 定位应用程序不再工作