Google Places API:如何在 Python 中按类型和位置进行搜索

Fra*_*ani 3 python google-maps google-places-api

我正在遵循我在GitHub主页上找到的示例googlemaps,我正在编写自己的代码,以便从特定区域检索所有电影院。

代码是这样的:

import googlemaps

gmaps = googlemaps.Client(key='MyGoogleKey')

search_loction = gmaps.location('40.714224, -73.961452').type('movie_theater')
print (search_loction)
Run Code Online (Sandbox Code Playgroud)

它返回给我错误:

Traceback (most recent call last):
  File "GoogleMap.py", line 5, in <module>
    search_loction = gmaps.location('40.714224, -73.961452')
AttributeError: 'Client' object has no attribute 'location'
Run Code Online (Sandbox Code Playgroud)

如果我按照指南,是的,该属性[location]是允许的 在此处输入图片说明

那么我做错了什么?

MrU*_*own 5

根据文档,您应该使用

gmaps.places(...)location作为参数。

就像是

gmaps.places(location=(lat,lng), type="movie_theater")

希望这可以帮助!