代码之家  ›  专栏  ›  技术社区  ›  Francesco Mantovani

Python googlemaps库和Google Places API调用与Postman的区别

  •  0
  • Francesco Mantovani  · 技术社区  · 6 年前

    当我使用这个GET调用从Google Places API和Postman检索JSON代码时:

    https://maps.googleapis.com/maps/api/place/nearbysearch/json?types=movie_theater&location=-36.8485,174.763336&radius=10000&key=PutYourAPIKeyHere
    

    我看到那之后 "types" "vicinity"

    enter image description here

    但是如果我用官方的 Google Maps Python library 为了检索相同的调用:

    import googlemaps
    gmaps = googlemaps.Client(key='PutYourAPIKeyHere')
    search_loction = gmaps.places("nearby",location='-36.8485, 174.763336', type="movie_theater")
    print (search_loction)
    

    我看到那之后 “类型” “附近” 方括号的结尾好像是这项业务的最后一个元素?

    enter image description here

    在我传递的Postman API调用中 nearbysearch 当我用Python传递 nearby .

    所以 一样 附近的

    如果不是,谷歌地图库的nearbysearch是什么?

    1 回复  |  直到 6 年前
        1
  •  -2
  •   Francesco Mantovani    6 年前

    我自己找到了解决办法,我会给像我这样挣扎的人贴出答案:

    import googlemaps
    
    gmaps = googlemaps.Client(key='PutYourAPIKeyHere')
    
    search_loction = gmaps.places_nearby(location='-36.8485, 174.763336', type="movie_theater",radius="10000")
    #print (search_loction)
    Total_Places_Found = 0
    
    
    if search_loction['status'] == 'OK':
        Total_Places_Found += len(search_loction['results'])
    
        for element in search_loction['results']:
            Place_ID = element['place_id']
            ID = element['id']
            Name = element['name']
            Latitude = element['geometry']['location']['lat']
            Longitude = element['geometry']['location']['lng']
            Rating = element['rating']
            Types = element['types']
            vicinity = element['vicinity']
            print (vicinity)