How to avoid both tolls and highways for Restricti

2019-05-31 17:00发布

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 ?

4条回答
地球回转人心会变
2楼-- · 2019-05-31 17:05

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

查看更多
干净又极端
3楼-- · 2019-05-31 17:13

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.

查看更多
Evening l夕情丶
4楼-- · 2019-05-31 17:15

&avoid=tolls|highways

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

查看更多
▲ chillily
5楼-- · 2019-05-31 17:27

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/

查看更多
登录 后发表回答