dc10
dc10

Reputation: 2208

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

Upvotes: 19

Views: 4676

Answers (1)

Gael
Gael

Reputation: 91

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

Upvotes: 2

Related Questions