Google 映射 python API 调用 nearby_places 函数时出错

Google maps python API error on calling nearby_places function

我在尝试调用 python api 中的 google 映射的 places_nearby 函数时出现 API 错误 https://github.com/googlemaps/google-maps-services-python/blob/master/googlemaps/places.py

gmaps = googlemaps.Client(key = maps_api_key)

places_result=gmaps.places_nearby(位置=(40.714224, -73.961452))

可能我叫错了。任何人都可以展示正确的方法来做到这一点。或者其他我需要修复的东西 错误图片附在下面: Api Error

正如我在您的屏幕截图中看到的,您正在获取 INVALID_REQUEST 状态代码。

根据 Places API 文档:

INVALID_REQUEST generally indicates that a required query parameter (location or radius) is missing.

来源:https://developers.google.com/places/web-service/search#PlaceSearchStatusCodes

确实,您在代码中指定了位置参数,但没有提供半径参数。仅当您在请求中指定 rankby=distance 时才可以省略半径参数。

看看nearby search documentation,上面写着:

radius — Defines the distance (in meters) within which to return place results. The maximum allowed radius is 50 000 meters. Note that radius must not be included if rankby=distance (described under Optional parameters below) is specified.

希望对您有所帮助!