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 2 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" or "ferries"
Copy link
Member

Choose a reason for hiding this comment

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

Add "indoor"

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


: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", "ferries"]
Copy link
Member

Choose a reason for hiding this comment

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

add "indoor"

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

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)


if units:
Expand Down