这是indexloc提供的服务,不要输入任何密码
Skip to content

Add parameter 'origin' to places autocomplete #392

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

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
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: 11 additions & 0 deletions googlemaps/places.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ def places_autocomplete(
input_text,
session_token=None,
offset=None,
origin=None,
location=None,
radius=None,
language=None,
Expand All @@ -537,6 +538,12 @@ def places_autocomplete(
service will match on 'Goo'.
:type offset: int

:param origin: The origin point from which to calculate straight-line distance
to the destination (returned as distance_meters).
If this value is omitted, straight-line distance will
not be returned.
:type origin: string, dict, list, or tuple

:param location: The latitude/longitude value for which you wish to obtain the
closest, human-readable address.
:type location: string, dict, list, or tuple
Expand Down Expand Up @@ -570,6 +577,7 @@ def places_autocomplete(
input_text,
session_token=session_token,
offset=offset,
origin=origin,
location=location,
radius=radius,
language=language,
Expand Down Expand Up @@ -623,6 +631,7 @@ def _autocomplete(
input_text,
session_token=None,
offset=None,
origin=None,
location=None,
radius=None,
language=None,
Expand All @@ -641,6 +650,8 @@ def _autocomplete(
params["sessiontoken"] = session_token
if offset:
params["offset"] = offset
if origin:
params["origin"] = convert.latlng(origin)
if location:
params["location"] = convert.latlng(location)
if radius:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_places.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def test_autocomplete(self):
"Google",
session_token=session_token,
offset=3,
origin=self.location,
location=self.location,
radius=self.radius,
language=self.language,
Expand All @@ -223,6 +224,7 @@ def test_autocomplete(self):
self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
"%s?components=country%%3Aau&input=Google&language=en-AU&"
"origin=-33.86746%%2C151.20709&"
"location=-33.86746%%2C151.20709&offset=3&radius=100&"
"strictbounds=true&types=geocode&key=%s&sessiontoken=%s"
% (url, self.key, session_token),
Expand Down