小编nex*_*xla的帖子

谷歌地图 python next_page_token 不起作用

我通过 google 地图库发送请求,得到 20 个地点的结果。

我的代码看起来像这样

gmaps = googlemaps.Client(key='MY_KEY_IS_HERE')

x = gmaps.places(query=['restaurants', 'bakery', 'cafe', 'food'],location='40.758896, -73.985130',radius=10000)

print len(x['results']) # outputs 20 (which is maximum per 1 page result)
Run Code Online (Sandbox Code Playgroud)

之后我想请求第二页,我认为我正确地使用了它。

print gmaps.places(page_token=x['next_page_token'].encode())
Run Code Online (Sandbox Code Playgroud)

它返回一个奇怪的错误

    File "/Users/././testz.py", line 15, in <module>
    print gmaps.places(page_token=x['next_page_token'].encode())
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/googlemaps/client.py", line 356, in wrapper
    result = func(*args, **kwargs)
TypeError: places() takes at least 2 arguments (2 given)
Run Code Online (Sandbox Code Playgroud)

我使用 .encode() 因为 unicode 中的“next_page_token”输出需要“str”。

知道我做错了什么以及如何解决它吗?

python google-maps google-places-api

5
推荐指数
1
解决办法
2388
查看次数

标签 统计

google-maps ×1

google-places-api ×1

python ×1