如何检索多个地方(placeids)的Google地方详细信息

时间:2016-06-09 09:52:00

标签: google-maps google-places-api

是否可以检索多个地方的地点详情?

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

该文档未提及有关解决多个地方的任何事情。

google places doc

1 个答案:

答案 0 :(得分:0)

您无法在单个请求中执行此操作。 您必须遍历一个场所ID列表,然后为每个场所拨打电话。

以下是使用此python包装器执行此操作的示例代码: /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