python - 如何使用 google-maps-services-python 按地点 id 反转地理编码位置

标签 python google-maps geolocation

我正在尝试使用 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/

相关文章:

javascript - 如何使谷歌地图的自定义叠加层位于标记的点击区域之上?

javascript - 尝试将 kml 图层添加到谷歌地图

python - 无需安装即可使用/导入 Beautiful Soup 4

python - 删除包含数组中内容的 pandas DataFrame 行

android - 如何从Android中的经纬度获取地址?

javascript - 使用谷歌地理位置 JSON

php - 地理距离搜索 MYSQL

javascript - 对多个 JavaScript 数组进行排序

python - 根据列表替换列中的项目

python - 语法错误 : unexpected EOF while parsing (using . 格式())