问题描述
我已经开发了一个由Google Places API驱动的应用程序。问题是地方在本地运行时正在加载,而不是在Google Cloud上部署后加载。我正在使用默认关键字来获取所需的结果,但是令人惊讶的是,它在部署后无法正常工作。我尝试更改关键字,但仍然返回0个结果。请在下面查看我的代码
await axios
.get("https://maps.googleapis.com/maps/api/place/nearbysearch/json",{
params: {
key: process.env.GOOGLE_PLACE_API_KEY,location: req.body.ll,radius: 20000,keyword: "popular destinations near me",},})
我得到的答复
{ html_attributions: [],results: [],status: 'ZERO_RESULTS' }
邮递员对相同作品的要求没有任何问题
以及使用原始JSON数据发送的同一请求,我遇到了错误
{
"key": "my key","location": "my location","radius": "20000","keyword": "popular destinations near me"
}
{
"error_message": "You must use an API key to authenticate each request to Google Maps Platform APIs. For additional @R_741_4045@ion,please refer to http://g.co/dev/maps-no-account","html_attributions": [],"results": [],"status": "REQUEST_DENIED"
}
使用邮递员发送的同一请求将返回20多个结果。我不知道上述要求可能有什么问题。谢谢您的任何帮助。
解决方法
Place API附近搜索“地方搜索”请求所需的参数,例如键,位置和半径。您也可以输入可选参数,它们是
keyword
(不是keywords
),
language
,
minprice
和maxprice
,
name
,
名称字段不再局限于地名。该字段中的值与关键字字段中的值组合在一起,并作为同一搜索字符串的一部分传递。我们建议仅对所有搜索词使用关键字参数。
opennow,rankby
,type
,pagetoken
。
因此,您不能为请求分配多个关键字。