【问题标题】:Can't get the Place details (Gmaps Places API) more than 20 data无法获取地点详情(Gmaps Places API)超过 20 条数据
【发布时间】: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


    【解决方案1】:

    如文档here中所述:

    默认情况下,每个附近搜索或文本搜索每个查询最多返回 20 个建立结果;但是,每次搜索最多可以返回 60 个结果,分成三个页面。

    所以基本上,您当前所经历的是一种预期的行为。您无法在一个附近的搜索查询中获得超过 20 个结果。

    如果在发送您的第一个附近搜索查询时返回了next_page_token,那么这意味着可以使用第二个包含结果的页面。

    要访问结果的第二页,就像您所做的那样,您只需发送另一个附近的搜索请求,但这次使用 pagetoken 参数,并使用您获得的 next_page_token 设置其值第一反应。

    如果next_page_token 也存在于您的第二个附近搜索查询的响应中,那么这意味着结果的第三页(和最后一个)也可用。您可以使用与访问第二页相同的方式访问结果的第三页。

    回到您的查询,我尝试了您指定的参数,但只能得到大约 9 个结果。你的radius参数是不是故意设置为300米?

    【讨论】:

    • 嗨!您有机会分享您用来执行此操作的代码吗?
    猜你喜欢
    • 1970-01-01
    • 2012-07-22
    • 1970-01-01
    • 1970-01-01
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    • 2016-03-20
    • 2017-01-06
    相关资源
    最近更新 更多