【发布时间】:2020-11-15 10:13:04
【问题描述】:
我正在尝试编写一个根据您当前位置显示温度的天气应用程序,使用 OpenWeatherApi,我收到错误 404 我不知道为什么
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
long = position.coords.longitude;
lat = position.coords.latitude;
console.log(position);
const api = `api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${long}&appid=74913cd6ec927a299e7fd99534e17b5f`;
fetch(api)
.then(response => {
return response.json();
})
.then(data => {
console.log(data);
});
});
我在控制台中遇到的错误:
【问题讨论】:
-
我看不出你的代码有什么问题。您确定 long/lat 和
appid有效吗? -
我遇到了同样的问题。你刚刚为我解决了。贾保佑你