如何通过google-maps-services-python的地方ID来反转地理编码位置

时间:2017-03-27 19:27:27

标签: python google-maps geolocation

我正在尝试使用https://github.com/googlemaps/google-maps-services-pythoncase 'c'反转地理位置位置,但结果我得到一个空数组。

placeId

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

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

1 个答案:

答案 0 :(得分: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

我希望这有帮助!