FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: multiple avoid problem by shaiguelman · Pull Request #417 · googlemaps/google-maps-services-python · GitHub

fix: multiple avoid problem - #417

Open
shaiguelman wants to merge 4 commits into
googlemaps:masterfrom
shaiguelman:master
Open

fix: multiple avoid problem#417
shaiguelman wants to merge 4 commits into
googlemaps:masterfrom
shaiguelman:master

Conversation

Copy link
Copy Markdown

Fixes #382

Modified distance_matrix so that the parameter "avoid" accepts multiple values, such as "tolls|highways".

google-cla Bot commented Sep 6, 2021

Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

google-cla Bot added the cla: no This human has *not* signed the Contributor License Agreement. label Sep 6, 2021

Copy link
Copy Markdown
Author

I have now signed the CLA, so that tag can be removed.

google-cla Bot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Nov 4, 2021
shaiguelman changed the title Fix multiple avoid problem Fix: multiple avoid problem Jan 29, 2022
shaiguelman changed the title Fix: multiple avoid problem fix: multiple avoid problem Apr 10, 2022

Copy link
Copy Markdown

@shaiguelman do you need to add another label describing the pr to have it merged?

wangela left a comment
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thank you for offering this fix and for your patience. Let me know if you're willing to make these changes, or if you'd prefer me to submit a patch to your fork.

Please also add this parameter to the distance matrix test, which you can model off the test of the multi-argument parameter in test_directions.py

Comment thread googlemaps/distance_matrix.py Outdated

: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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Add "indoor"

indicated features. Valid values are "tolls", "highways" or "ferries".
indicated features. Valid values are "tolls", "highways" or "ferries"
as well as any combination of them separated by "|".
:type avoid: string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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?

Comment thread googlemaps/distance_matrix.py Outdated
if avoid:
if avoid not in ["tolls", "highways", "ferries"]:
raise ValueError("Invalid route restriction.")
valid_avoids = ["tolls", "highways", "ferries"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

add "indoor"

for token in avoid_tokens:
if token not in valid_avoids:
raise ValueError("Invalid route restriction.")
valid_avoids.remove(token)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think you mean to remove from avoid_tokens

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

if token not in valid_avoids:
raise ValueError("Invalid route restriction.")
valid_avoids.remove(token)
params["avoid"] = avoid

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Author

@wangela Sorry for the late response. Haven't checked this personal github account in a while. Added "indoor" option and replied to your other comments

shaiguelman requested a review from wangela September 23, 2025 21:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiple avoid problems

3 participants


Back | FazBrowse Home | New Git URL