【发布时间】:2021-07-06 21:45:07
【问题描述】:
我目前正在编写一个天气应用程序(为了好玩),它可以获取用户的经度和纬度(经许可),然后显示当前天气。不幸的是,天气数据没有正确记录在控制台中。任何帮助将不胜感激!谢谢!
const api = "API---";
window.addEventListener('load', () => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
let lat = position.coords.latitude;
let lon = position.coords.latitude;
let data = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${api}`;
console.log(lat, lon, data);
fetch(data)
.then((r) => {
return r.JSON;
})
.then((data) => {
console.log(data);
})
});
};
});
记录的不是天气,而是记录
ƒ json() { [native code] }
我使用的是开放天气,但 API 密钥不会公开显示。感谢您的帮助!
【问题讨论】:
标签: javascript weather openweathermap