【问题标题】:How to reverse geocode location by place id with google-maps-services-python如何使用 google-maps-services-python 按地点 ID 反转地理编码位置
【发布时间】:2017-03-27 19:27:26
【问题描述】:

我正在尝试使用https://github.com/googlemaps/google-maps-services-python 通过placeId 反转地理编码位置,但结果是一个空数组。

gmaps = googlemaps.Client(key='<my-api-key>')
place_id = "ChIJnQrgk4u6EmsRVqYSfnjhaOk"
location = gmaps.geolocate({'placeId':place_id})

位置返回为[]

我该怎么做,因为该库的文档不是最好的。

【问题讨论】:

  • 好吧,另一种方法是首先获取您正在获取的 PlaceID 的坐标,然后对该 corrdinats 使用反向地理编码。 Google Maps JavaScript documentation 中有一个示例代码,您可以使用 Place ID 获取坐标。欲了解更多信息,请查看相关question

标签: python google-maps geolocation


【解决方案1】:

您正在尝试使用 gmaps.geolocate,但这是为了使用地理定位 API,而不是地理编码 API。您需要使用此处记录的反向地理编码器:

https://googlemaps.github.io/google-maps-services-python/docs/2.4.6/

我能够使用以下代码使其工作:

import googlemaps

gmaps = googlemaps.Client(key='MY_API_KEY')
place_id = "ChIJnQrgk4u6EmsRVqYSfnjhaOk"
# Geocoding an address
geocode_result = gmaps.reverse_geocode(place_id)


print geocode_result

我希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-23
    相关资源
    最近更新 更多