Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve google place details for multiple places (placeids)

Is it possible to retrieve place details for multiple places?

https://maps.googleapis.com/maps/api/place/details/json?placeid=[ArrayInsteadOfJustOnePlaceId]

The documentation does not mention anything regarding the resolving of multiple places.

google places doc

like image 989
dc10 Avatar asked Jun 09 '16 09:06

dc10


People also ask

How do I get data from Google Maps Places API?

Go to APIs & Services → Dashboard → Enable APIs & Services at the top and Choose Maps Javascript API from the API Library. This will open up the Map JavaScript API page, and Enable it.

Can you store Google Places data?

So no, you are not allowed to store this data indefinitely. Recent policy changes removed the 30 days caching statement and added a statement about not cacheing any ratings data. When asked for clarification from Google, Google stated any and all data cached from Places API must be deleted.


1 Answers

You can't do it in a single request. You have to iterate over a list of place id and make a call for each.

Here is a sample code to do it using this python wrapper: /slimkrazy/python-google-places

pip install python-google-places
from googleplaces import GooglePlaces, GooglePlacesAttributeError, GooglePlacesError

GOOGLE_API_KEY = 'AIzaSyDRcaVMH1F_H3pIbm1T-XXXXXXXXXXX'
GOOGLE_PLACE_IDS = [
    "ChIJC4Wu9QmvthIRDmojjnJB6rA",
    "ChIJuRFUv33Ew0cRk0JQb2xQOfs",
    "ChIJ9yGYrIwd9kcRlV-tE8ixHpw"
  ]

def main():
 google_places = GooglePlaces(GOOGLE_API_KEY)
 for place_id in GOOGLE_PLACE_IDS:
     try:
         place = google_places.get_place(place_id)
         print('{0} place_id has name {1}'.format(place_id, place.name))

     except (GooglePlacesError, GooglePlacesAttributeError) as error_detail:
         print('Google Returned an Error : {0} for Place ID : {1}'.format(error_detail, place_id))
         pass

like image 86
Gael Avatar answered Sep 18 '22 15:09

Gael