【发布时间】:2019-07-12 09:13:18
【问题描述】:
使用 Google 的 API,我可以将附近的地点打印到控制台
router.get('/', function (req, res, next) {
// Find places nearby
googleMapsClient.placesNearby({
language: 'en',
location: [-33.865, 151.038],
radius: 500,
type: 'restaurant'
})
.asPromise()
.then((response) => {
console.log(response.json.results);
})
.catch((err) => {
console.log(err);
});
});
我想将包含附近所有地点的响应发送给客户端,以便我可以使用 pug 在表格中打印它们。
当我尝试res.send(response.json.results 时,我无法发送该数据
我收到Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
【问题讨论】:
-
您的代码中没有
response.send()这样的东西,只有res.send()。如果仍有问题,请花 30 秒时间重新阅读您的代码并编辑您的问题。 -
错了。响应来自谷歌的。和快速路线的资源。
-
检查`.then((response) => {`
-
我很高兴你编辑了,但你之前的帖子提到了
TypeError: response.send is not a function,我说 response.send() 不可能是一件事;) -
你能准确地添加 res.send(response.json.results) 吗?
标签: javascript node.js google-maps express