python - 在 Google Places api 中搜索附近的 lat_lng (python)

标签 python google-maps google-api google-places-api

我正在尝试查找 lat_lng 中某个位置附近的所有地点。但是,在搜索 lat_lng 而不是位置 (location='location') 时出现错误。我有 Google 地点 API Web 服务和 Google map 地理编码 API 的 key 。根据https://github.com/slimkrazy/python-google-places这应该足够了。

这是我的代码和错误消息:

YOUR_API_KEY = 'API_KEY'
google_places = GooglePlaces(YOUR_API_KEY)

query_result = google_places.nearby_search(
        lat_lng='52.0737017, 5.0944107999999915', 
        radius=100,
        types=[types.TYPE_RESTAURANT] or [types.TYPE_CAFE])

for place in query_result.places:
     place.get_details()
     print '%s %s %s' % (place.name, place.geo_location, place.types)

错误消息:

File "C:\Python27\lib\site-packages\googleplaces\__init__.py", line 281, in nearby_search
    lat_lng_str = self._generate_lat_lng_string(lat_lng, location)
  File "C:\Python27\lib\site-packages\googleplaces\__init__.py", line 590, in _generate_lat_lng_string
    else geocode_location(location=location, api_key=self.api_key))
TypeError: format requires a mapping

谁知道如何解决这个问题?

最佳答案

来自github您提供的,引用部分指出 lat_lng 参数的类型为 dict:

lat_lng -- A dict containing the following keys: lat, lng (default None)

请执行以下操作:

query_result = google_places.nearby_search(
        lat_lng={'lat': 52.0737017, 'lng': 5.0944107999999915}, 
        radius=100,
        types=[types.TYPE_RESTAURANT] or [types.TYPE_CAFE])

要查看 query_result,只需执行以下操作:

query_result.raw_response

关于python - 在 Google Places api 中搜索附近的 lat_lng (python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48208227/

相关文章:

python - 计算数据帧每一行中元素的出现次数

javascript - ACF 谷歌地图字段未呈现

php - 在 Google API v2 中,为什么会发生错误 "The project id used to call the Google Play Developer API has not been linked"?

javascript - Google Sheets API 读取单元格 (Javascript)

python - 无法覆盖由monkeypatch 为单例类设置的函数的初始值

python - Numpy.where : very slow with conditions from two different arrays

python - 给定一个带有空格的英语句子,我如何在 python 中估计特定单词适合该空格的概率?

google-maps - 更改Google map 标记

javascript - 当用户点击谷歌地图网站时,可能已经选中了复选框吗?

r - 如何通过GA API访问唯一的客户端ID?