我正在使用 Google Places API 和 Python 来构建一个食品集体智能应用程序。例如周围有哪些餐厅,他们的评级如何,营业时间是什么,等等
我正在Python中执行以下操作:
from googleplaces import GooglePlaces, types, lang
API_KEY = ''
google_places = GooglePlaces(API_KEY)
query_result = google_places.nearby_search(
location='Mumbai', keyword='Restaurants',
radius=1000, types=[types.TYPE_RESTAURANT])
if query_result.has_attributions:
print query_result.html_attributions
for place in query_result.places:
print place.name
print place.geo_location
print place.place_id
它返回给我这样的东西:
Subway
{u'lat': Decimal('19.1156005'), u'lng': Decimal('72.9090715')}
ChIJV2JWaObH5zsRt-FrEb8lrtM
Aroma's Cafe
{u'lat': Decimal('19.116867'), u'lng': Decimal('72.90982199999999')}
ChIJSWijB-bH5zsRVLE5ipsxvHU
Chili's
{u'lat': Decimal('19.1161942'), u'lng': Decimal('72.90909789999999')}
ChIJ4_2UcubH5zsRWMemt2WTsLc
Mainland China
{u'lat': Decimal('19.1154358'), u'lng': Decimal('72.90858159999999')}
ChIJ88dcaObH5zsRWLT4KyCLkI8
The Yellow Chilli
现在我想了解每家餐厅的详细信息(比如他们的评分、评论、营业时间)。如何使用
place_id
检索信息?
请参阅此(向下滚动查看文档):
https://github.com/slimkrazy/python-google-places
它有您需要的所有电话。例如:
for place in query_result.places:
place.get_details()
print place.rating
将获得您每个地点的评分。几乎所有内容都在 github 链接中:)
添加到最简单的解决方案,如果您想从 place_id 获取更多信息/详细信息,您可以使用:
import googlemaps
gmaps = googlemaps.Client("secret")
for place in query_result.places:
gmaps.place(place.place_id)