问题
I try to find the shortest route from Lone Pine, CA to Yosemite Village, CA.
A simple Google Maps lookup reveals two routes:
- Toll routes: US-395N, CA-120W ~316 km
- No toll routes: CA-99N ~596 km
DirectionService/DistanceMatrixService have an avoidTolls parameter:
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.
I expect the services to return route #1 when applying avoidTolls: false, but instead route #2 is returned.
Is my expectation or my implementation http://jsfiddle.net/nQzD8/2 flawed?
Update:
As Dr. Molle pointed out, route #1 is ignored not because of the toll routes included but because it might be closed at the current time ("This road may be seasonally closed." in the directions step).
user2961817 found out, that the 316km result can be obtained by avoiding Highways (setting avoidHighways: true).
Are there other options to retrieve a DistanceMatrix result for another time of the year besides becoming a Maps for Business customer and use the DistanceMatrix API with the departure_time parameter?
Solution:
Route #1 is ignored because it might be closed at the time of the request and not because there are toll routes included. In order to retrieve the shorter route there are the following options:
DistanceMatrixService:
- Become a Business customer and set the departure_time parameter.
- Issue a 2nd request with
avoidHighways: trueand take the shorter route (happens to work in this particular case but won't in most other cases)
DirectionService:
- Use
provideRouteAlternatives:true, iterate through alternatives and take the shortest one
回答1:
When I explicitly draw a direction via CA-120 W I get the following information for this road: This road may be seasonally closed . Maybe that's the reason why google avoids this road.
The Tioga Road closes due to snow, usually from sometime in November through late May or early June. ...it's november
回答2:
Seems to work for me. When set to true it displays a different route then when set to false.
Expected result: 316 km via US-395 N and CA-120 W
来源:https://stackoverflow.com/questions/19819586/google-maps-v3-distancematrix-directions-ignore-avoidtollsfalse