Google地图API在一个

2024-03-28 15:17:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我想把一个地区所有的“药店/药房”都刮干净,但我只得到有限的数量,而不是全部。你知道吗

有没有办法一次获得所有的json数据?你知道吗

url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?"
location = "33.589886, -7.603869"
radius = 26000
place_type = "pharmacy"
language = "fr"
r = requests.get(url + '&location=' +str(location)+'&radius='+str(radius) +   
'&type='+place_type+'&language='+language+'&key=' + api_key) 

我只得到20个,而我想得到整个半径。你知道吗


Tags: keyapijsonurl数量typeplacelocation
1条回答
网友
1楼 · 发布于 2024-03-28 15:17:53

根据documentation,Places API最多返回20个结果:

The Places API returns up to 20 establishment results per query

然后,您应该使用next_page_token生成一个新查询并获得下一页的结果:

next_page_token contains a token that can be used to return up to 20 additional results. A next_page_token will not be returned if there are no additional results to display. The maximum number of results that can be returned is 60. There is a short delay between when a next_page_token is issued, and when it will become valid.

示例:

next_page_token = r.json().get('next_page_token')

while next_page_token:
    r = requests.get(url + '&pagetoken=' + next_page_token)

    # Parse the results page

    next_page_token = r.json().get('next_page_token')

相关问题 更多 >