Skip to content
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

Support reverse_geocode by place_id #110

Merged
merged 5 commits into from
Mar 15, 2016
Merged

Conversation

wilkens
Copy link
Contributor

@wilkens wilkens commented Jan 13, 2016

Add support for reverse geocoding by place_id in addition to existing lat/lng. Doesn't change interface, just checks for a string that begins with something other than a digit or a +/- sign. Treats such strings as place_ids, otherwise behaves like current code.

If reverse_geocode is passed a string that does not begin with a digit
or a + or - sign, assume it's a place_id rather than a latlng
coordinate and treat appropriately.
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. 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, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@wilkens
Copy link
Contributor Author

wilkens commented Jan 13, 2016

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

Python3 lacks 'unicode' type. Need different approach to catch unicode
strings in Python2.
@wilkens
Copy link
Contributor Author

wilkens commented Jan 14, 2016

Ick, proposed code failed on python3 due to lack of 'unicode' string type. New version in python3 only; works on python2, but fails for unicode-encoded place_ids in that case.

@@ -90,7 +90,10 @@ def reverse_geocode(client, latlng, result_type=None, location_type=None,
:rtype: list of reverse geocoding results.
"""

params = {"latlng": convert.latlng(latlng)}
if (type(latlng) == str) & (latlng[0] not in ("-+0123456789")):
Copy link
Contributor

Choose a reason for hiding this comment

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

Few problems:

  • As you pointed out, the type check fails. How about convert.is_string(latlng) ?
  • & should be and
  • Looks like Place IDs contain alphanumeric chars and dashes, so there's a chance latlng[0] not in ("-+0123456789") would fail if the first character in a place ID was a digit. Since the string version of a latlng would contain a comma and a Place ID wouldn't, how about checking for that?

Use convert.is_string to do 2/3-safe string detection
If string, test for comma; if no comma, then place_id
@wilkens
Copy link
Contributor Author

wilkens commented Mar 15, 2016

Implemented suggested changes from @stephenmcd. Thanks and hope this is good to go.

@@ -90,7 +90,10 @@ def reverse_geocode(client, latlng, result_type=None, location_type=None,
:rtype: list of reverse geocoding results.
"""

params = {"latlng": convert.latlng(latlng)}
if (convert.is_string(latlng) and (',' not in latlng)):
Copy link
Contributor

Choose a reason for hiding this comment

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

Almost there - most of those parentheses aren't necessary, so just:

if convert.is_string(latlng) and ',' not in latlng:

Could probably also use a comment mentioning why we check for a comma

Remove extraneous parens.
Add comment on logic detecting place_id as parameter.
@wilkens
Copy link
Contributor Author

wilkens commented Mar 15, 2016

Thanks for your patience, @stephenmcd. Let me know if we need further changes!

@stephenmcd
Copy link
Contributor

No problem at all, thanks for actioning all the feedback!

stephenmcd added a commit that referenced this pull request Mar 15, 2016
Support reverse_geocode by place_id
@stephenmcd stephenmcd merged commit 519ee85 into googlemaps:master Mar 15, 2016
@rbouchez rbouchez mentioned this pull request Jun 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants