我尝试找到从加利福尼亚隆派恩到加利福尼亚优胜美地村的最短路线。

一个简单的Google Maps查找将显示两条路线:


收费公路:US-395N,CA-120W〜316 km
免费电话:CA-99N〜596公里


DirectionService / DistanceMatrixService具有voidTolls参数:

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发现,通过避开高速公路(设置avoidHighways: true)可以获得316公里的结果。

除了成为Maps for Business客户并使用带有departure_time参数的DistanceMatrix API之外,还有其他选择可用于在一年中的其他时间检索DistanceMatrix结果吗?

解:

路线1被忽略,因为它可能会在请求时关闭,而不是因为其中包含收费路线。为了检索更短的路线,有以下选项:

DistanceMatrixService:


成为企业客户,并设置离开时间参数。
avoidHighways: true发出第二个请求,取较短的一个
路线(在这种情况下可能会起作用,但在大多数情况下不会起作用
其他情况)


DirectionService:


使用provideRouteAlternatives:true,遍历替代方案并
选最短的一个

最佳答案

当我通过CA-120 W明确绘制方向时,会获得以下关于该道路的信息:该道路可能季节性关闭。也许这就是Google避开这条路的原因。

The Tioga Road closes due to snow, usually from sometime in November through late May or early June. ...十一月

07-24 17:16
查看更多