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

feat: Geocode by place id #427

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
Feb 2, 2022
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
9 changes: 8 additions & 1 deletion googlemaps/geocoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from googlemaps import convert


def geocode(client, address=None, components=None, bounds=None, region=None,
def geocode(client, address=None, place_id=None, components=None, bounds=None, region=None,
language=None):
"""
Geocoding is the process of converting addresses
Expand All @@ -30,6 +30,10 @@ def geocode(client, address=None, components=None, bounds=None, region=None,
:param address: The address to geocode.
:type address: string

:param place_id: A textual identifier that uniquely identifies a place,
returned from a Places search.
:type place_id: string

:param components: A component filter for which you wish to obtain a
geocode, for example: ``{'administrative_area': 'TX','country': 'US'}``
:type components: dict
Expand All @@ -53,6 +57,9 @@ def geocode(client, address=None, components=None, bounds=None, region=None,
if address:
params["address"] = address

if place_id:
params["place_id"] = place_id

if components:
params["components"] = convert.components(components)

Expand Down
19 changes: 19 additions & 0 deletions tests/test_geocoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,25 @@ def test_geocode_with_just_components(self):
responses.calls[0].request.url,
)

@responses.activate
def test_geocode_place_id(self):
responses.add(
responses.GET,
"https://maps.googleapis.com/maps/api/geocode/json",
body='{"status":"OK","results":[]}',
status=200,
content_type="application/json",
)

results = self.client.geocode(place_id="ChIJeRpOeF67j4AR9ydy_PIzPuM")

self.assertEqual(1, len(responses.calls))
self.assertURLEqual(
"https://maps.googleapis.com/maps/api/geocode/json?"
"key=%s&place_id=ChIJeRpOeF67j4AR9ydy_PIzPuM" % self.key,
responses.calls[0].request.url,
)

@responses.activate
def test_simple_reverse_geocode(self):
responses.add(
Expand Down