Skip to content

fix: multiple avoid problem #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions googlemaps/distance_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def distance_matrix(client, origins, destinations,
:type language: string

:param avoid: Indicates that the calculated route(s) should avoid the
indicated features. Valid values are "tolls", "highways" or "ferries".
indicated features. Valid values are "tolls", "highways", "indoor" or "ferries"
as well as any combination of them separated by "|".
:type avoid: string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To mirror the implementation in directions.py, let's update this to list or string

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case it wouldn't work with a list since we're calling the split function. Would you like me to add an if check before calling split?


:param units: Specifies the unit system to use when displaying results.
Expand Down Expand Up @@ -107,8 +108,12 @@ def distance_matrix(client, origins, destinations,
params["language"] = language

if avoid:
if avoid not in ["tolls", "highways", "ferries"]:
raise ValueError("Invalid route restriction.")
valid_avoids = ["tolls", "highways", "indoor", "ferries"]
avoid_tokens = avoid.split("|")
for token in avoid_tokens:
if token not in valid_avoids:
raise ValueError("Invalid route restriction.")
valid_avoids.remove(token)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean to remove from avoid_tokens

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is meant to avoid repeats (i.e. "tolls | tolls"). So once it's already used one then it removes it from the list of valid tokens. I can add a comment to explain or remove it if you want repeats to be valid. Please let me know

params["avoid"] = avoid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to set it to the value of avoid_tokens right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's where we could do parallel implementation with directions.py.
How about:

params["avoid"] = convert.join_list("|", avoid_tokens)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, just seems redundant to rejoin the string instead of just using the version that was never split


if units:
Expand Down