我正在尝试使用 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})
位置以 []
形式返回。
我该怎么做,因为该库的文档不是最好的。
最佳答案
您正在尝试使用 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
希望这会有所帮助!
关于python - 如何使用 google-maps-services-python 按地点 id 反转地理编码位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43054852/