【发布时间】:2013-11-06 18:13:09
【问题描述】:
我试图找到从 Lone Pine, CA 到 Yosemite Village, CA 的最短路线。
一个简单的谷歌地图查找揭示了两条路线:
- 收费路线:US-395N、CA-120W ~316 公里
- 无收费路线:CA-99N ~596 公里
DirectionService/DistanceMatrixService 有一个 AvoidTolls 参数:
avoidTolls (optional) — If true, the directions between points will be calculated using non-toll routes, wherever possible.
avoidTolls (optional) when set to true indicates that the calculated route(s) should avoid toll roads, if possible.
我希望服务在应用 avoidTolls: false 时返回路由 #1,但返回的是路由 #2。
我的期望或我的实施http://jsfiddle.net/nQzD8/2 有缺陷吗?
更新:
作为博士。 Molle 指出,忽略 1 号路线不是因为包含收费路线,而是因为它可能在当前时间关闭(“这条道路可能会季节性关闭。”在方向步骤中)。
user2961817发现,避开Highways(设置avoidHighways: true)可以获得316km的结果。
除了成为 Maps for Business 客户并使用带 departure_time 参数的 DistanceMatrix API 之外,还有其他选项可以检索一年中另一个时间的 DistanceMatrix 结果吗?
解决方案:
Route #1 被忽略,因为它可能在请求时关闭,而不是因为包含收费路线。为了检索较短的路线,有以下选项:
DistanceMatrixService:
- 成为商业客户并设置离开时间参数。
- 使用
avoidHighways: true发出第二个请求并取较短的 路线(在这种特殊情况下会起作用,但在大多数情况下不会 其他情况)
DirectionService:
- 使用
provideRouteAlternatives:true,遍历备选方案和 取最短的一个
【问题讨论】:
-
只有当 provideRouteALternatives 为 true 且 AvoidTolls 为 false 时,它才会为我返回较短的路线。 jsfiddle.net/nQzD8/8
标签: javascript google-maps google-maps-api-3