【发布时间】:2020-08-24 08:03:32
【问题描述】:
我是 Python 的新手,尤其是使用 Gmaps API 来获取地点详细信息。
我想用这个参数搜索地点:
places_result = gmaps.places_nearby(location=' -6.880270,107.60794', radius = 300, type = 'cafe')
但实际上我想在特定的纬度/经度和半径中尽可能多地获取数据。因此,我尝试获取 google api 提供的新参数。那是page_token。这是文档的详细信息:
pagetoken — 从以前运行的搜索中返回最多 20 个结果。设置 pagetoken 参数将使用之前使用的相同参数执行搜索——除了 pagetoken 之外的所有参数都将被忽略。 https://developers.google.com/places/web-service/search
所以我尝试使用此功能获取更多数据(下一页数据):
places_result = gmaps.places_nearby(location=' -6.880270,107.60794', radius = 300, type = 'cafe')
time.sleep(5)
place_result = gmaps.places_nearby(page_token = places_result['next_page_token'])
这是我的全部输出功能:
for place in places_result['results']:
my_place_id = place['place_id']
my_fields = ['name','formatted_address','business_status','rating','user_ratings_total','formatted_phone_number']
places_details = gmaps.place(place_id= my_place_id , fields= my_fields)
pprint.pprint(places_details['result'])
但不幸的是,当我开始跑步时,我只能获得 20 个(最多)地点详细信息的数据。不知道我的page token参数函数是不是真的,因为输出不能超过20条数据。
我非常感谢任何可以给我建议以解决问题的人。非常感谢:)
【问题讨论】:
标签: python google-maps google-places-api