how to get place details from place id in google places api for python

末鹿安然 提交于 2019-12-12 07:37:34

问题


I am using the Google Places API with Python to build a collective intelligence app for food. e.g. what restaurants are around, what ratings they have, what are their timings, etc.

I am doing the following in 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  

And it returns me something like this:

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

Now I want to have the details of each restaurant (like their ratings, reviews, timings). How can the information be retrieved with place_id?


回答1:


Refer to this (scroll down for the documentation):

https://github.com/slimkrazy/python-google-places

It's got all of the calls you need. For example:

for place in query_result.places:
    place.get_details()
    print place.rating

Will get the ratings for each of your places. Pretty much everything is in that github link for you :)



来源:https://stackoverflow.com/questions/34282235/how-to-get-place-details-from-place-id-in-google-places-api-for-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!