【问题标题】:How to use the Google Places Python API to look up a place by name如何使用 Google Places Python API 按名称查找地点
【发布时间】:2021-09-08 07:59:50
【问题描述】:

如何使用 Google Maps Python API 按名称查找地点?

深入研究测试并解码fields 值我花了一点时间,所以我想在我运行后发布我的工作示例。

更多阅读:

【问题讨论】:

标签: python google-places-api


【解决方案1】:
from environs import Env
import googlemaps
maps_api = googlemaps.Client(key=env("PLACES_API_KEY"))

place_search = maps_api.find_place(
            "St. Louis Lambert International Airport",
            "textquery",
            fields=["formatted_address", "place_id"],
            language='en-US',
        )

print("Place search results")
pprint(place_search)

place_lookup = maps_api.place(
        place_search["candidates"][0]["place_id"], fields=["website", "place_id"])

print("\nPlace lookup results")
pprint(place_lookup)

...

/usr/bin/python3 /work/project/scripts/address-duplicate-locator/main.py
Place search results
{'candidates': [{'formatted_address': '10701 Lambert International Blvd, St. '
                                      'Louis, MO 63145, United States',
                 'place_id': 'ChIJ8YhjxbQ234cRpncwZrzNq50'}],
 'status': 'OK'}

Place lookup results
{'html_attributions': [],
 'result': {'place_id': 'ChIJ8YhjxbQ234cRpncwZrzNq50',
            'website': 'http://www.flystl.com/'},
 'status': 'OK'}

Process finished with exit code 0

您可以使用从https://github.com/googlemaps/google-maps-services-python/blob/master/googlemaps/places.py 提取的 Places API 查找的完整列表:

PLACES_FIND_FIELDS_BASIC = {"business_status",
        "formatted_address",
        "geometry",
        "geometry/location",
        "geometry/location/lat",
        "geometry/location/lng",
        "geometry/viewport",
        "geometry/viewport/northeast",
        "geometry/viewport/northeast/lat",
        "geometry/viewport/northeast/lng",
        "geometry/viewport/southwest",
        "geometry/viewport/southwest/lat",
        "geometry/viewport/southwest/lng",
        "icon",
        "name",
        "permanently_closed",
        "photos",
        "place_id",
        "plus_code",
        "types",}

【讨论】:

    猜你喜欢
    • 2013-08-30
    • 1970-01-01
    • 2013-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-14
    相关资源
    最近更新 更多