在 Google 个地方使用 Fetch API
Using Fetch with Google Places API
嗨,这可能是一个非常菜鸟的错误,但是有人知道为什么 console.logging 未定义吗?当我向浏览器提交 url 时,我得到有效的 json 响应。谢谢
fetch('https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=[API KEY HERE]&location=49.246292,-123.116226&radius=500000')
.then((resp) => {
resp.json();
})
.then((data) => {
console.log(data);
})
.catch(err => console.error(err));
因为您已决定将箭头函数体包裹在花括号中,所以您需要专门 return 数据:
.then((resp) => {
return resp.json();
})
或者删除大括号:
.then(resp => resp.json())
嗨,这可能是一个非常菜鸟的错误,但是有人知道为什么 console.logging 未定义吗?当我向浏览器提交 url 时,我得到有效的 json 响应。谢谢
fetch('https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=[API KEY HERE]&location=49.246292,-123.116226&radius=500000')
.then((resp) => {
resp.json();
})
.then((data) => {
console.log(data);
})
.catch(err => console.error(err));
因为您已决定将箭头函数体包裹在花括号中,所以您需要专门 return 数据:
.then((resp) => {
return resp.json();
})
或者删除大括号:
.then(resp => resp.json())