pythongoogle-places-api

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


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?


Solution

  • 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 :)