2

Google Directions API allows us to attempt to avoid tolls by supplying the argument &avoid=tolls.

Also, we can attempt to avoid highways by supplying the argument &avoid=highways.

I was wondering how do I supply the arguments for avoiding both tolls and highways?

Is it &avoid=tolls|highways or &avoid=tolls,highways ?

Pacerier
  • 86,231
  • 106
  • 366
  • 634
  • Have you *tried* either? – Rowland Shaw Jan 19 '12 at 08:47
  • @RowlandShaw yep, but the returned results are the same no matter what I put. The guys at http://groups.google.com/group/google-maps-api-web-services/browse_thread/thread/7dff69e69066845c are also ignoring this question.. – Pacerier Jan 19 '12 at 12:15
  • There's a difference between ignoring and not knowing the answer (as it doesn't appear to be documented) – Rowland Shaw Jan 19 '12 at 15:35
  • Well, I can't construct a route (mentally) where there are alternates avoiding tolls and highways; all the tolls I know of are either on highways (so avoiding highways avoids the tolls) or are in such small locations that you wouldn't need to be avoiding highways as well. – Rowland Shaw Feb 02 '12 at 08:49
  • @RowlandShaw Well that doesn't mean the documentation should be quiet about this. For example, if there's no info we don't even know if it's illegal to put in a `&avoid=tolls|highways`. Btw why did you vote to close? – Pacerier Feb 02 '12 at 09:54
  • You are right that the valid values should be documented by the vendor of the API (i.e. Google); it may be that the valid values are documented, and the option to avoid both is not supported by them. This is not the sort of thing that an outsider from Google could categorically state. You could do your own analysis (find a route that has an option that avoids tolls, but would normally use them, then check is avoiding highways and tolls still avoids it; repeat for a highway/avoidable highway route; but as it is not documented, don't rely on the implementation remaining fixed) – Rowland Shaw Feb 02 '12 at 12:57
  • Any success with this question ? – Grigory Feb 08 '12 at 15:41
  • @Beloru not at all. None is able to help. – Pacerier Feb 10 '12 at 06:44
  • @Belorus remember to post the answer if you have it! – Pacerier Feb 10 '12 at 06:45

4 Answers4

2

&avoid=tolls|highways

Search for "avoid=tolls|highways|ferries" on: https://developers.google.com/maps/documentation/directions/

1

I'm stuck on the "attempt to" avoid highways and tolls too. The docs clearly state "Note: the addition of restrictions does not preclude routes that include the restricted feature; it simply biases the result to more favorable routes"...so favorable = ignored arguments.

You can pass in both arguments...http://maps.google.com/maps/api/directions/xml?alternatives=true&units=imperial&avoid=tolls&avoid=highways...

Here's a link to the latest docs.... https://developers.google.com/maps/documentation/directions/

Greg Sipes
  • 683
  • 6
  • 16
  • Even the maps api linked in the answer doesn't do the job. You can verify by: https://maps.googleapis.com/maps/api/directions/json?origin=58.6739164,14.9656690&destination=58.657812,14.958812&mode=walking&alternatives=true&avoid=highways&key= It does give the path which goes through Highway 50 – Chanchal Raj Sep 01 '19 at 10:25
1

I ran into the same issue, so I did some tests and it appears as if &avoid=tolls|highways is the correct usage.

Going from Portland, OR to San Francisco, CA has tolls and highways. If you go to maps.google.com and route between the two, selecting different options, you find that Google gives you the same route for avoiding highways as avoiding highways and tolls.

When doing an API request &avoid=tolls|highways results in the same as &avoid=highways|tolls.

&avoid=tolls,highways results in not avoiding either.

&avoid=tolls&avoid=highways results in only avoiding tolls.

This all leads me to infer that Google must be reading both variables when you pass them with a |. however, avoiding tolls and highways often results in the same directions as just avoiding highways.

garrettmoon
  • 139
  • 2
  • 11
1

Currently there seems to be a bug in the Google Directions API (not the client library). Multiple restrictions are not identified, e.g.&avoid=highways|tolls does not work but single do &avoid=highways and &avoid=tolls.

See answer: https://productforums.google.com/forum/#!topic/maps/WSp_qn6ou6I

I've opened a bug ticket for this on the Directions API bug tracker as there was none there already https://code.google.com/p/gmaps-api-issues/issues/detail?id=10696

Sverrir Sigmundarson
  • 2,453
  • 31
  • 27