Pacerier
Pacerier

Reputation: 89663

How to avoid both tolls and highways for Restrictions in Google Directions API?

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 ?

Upvotes: 2

Views: 6946

Answers (4)

Sverrir Sigmundarson
Sverrir Sigmundarson

Reputation: 2631

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

Upvotes: 1

user1135204
user1135204

Reputation: 31

&avoid=tolls|highways

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

Upvotes: 2

garrettmoon
garrettmoon

Reputation: 139

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.

Upvotes: 1

Greg Sipes
Greg Sipes

Reputation: 703

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/

Upvotes: 1

Related Questions