采用开放式天气预报系统(一个信号2.5),在某个地区使用6天以前的天气数据,为什么在JSON数据中没有降水?
是否有这方面的数据,如果有的话,我如何利用一项召回的2.5项吉大港山区的请求获得数据?
我的全文如下:
const API_KEY = "XXX";
const LATITUDE = 26.640629;
const LONGITUDE = -81.872307;
const endDate = new Date();
const startDate = new Date(endDate.getTime() - (5 * 24 * 60 * 60 * 1000));
async function getWeatherData() {
try {
const weatherDataList = [];
for (let date = startDate; date <= endDate; date.setDate(date.getDate() + 1)) {
const weatherData = await (await fetch(`https://api.openweathermap.org/data/2.5/onecall/timemachine?lat=${LATITUDE}&lon=${LONGITUDE}&dt=${Math.floor(date.getTime() / 1000)}&appid=${API_KEY}&units=imperial`)).json();
const weatherDataLocalList = [];
weatherDataLocalList.push(weatherData.current.temp);
weatherDataLocalList.push(weatherData.current.humidity);
weatherDataLocalList.push(weatherData.current.pressure * 0.02952998751);
weatherDataLocalList.push(weatherData.current.wind_speed * 0.44704);
weatherDataLocalList.push(1);
weatherDataList.push(weatherDataLocalList);
}
predict2(weatherDataList);
} catch (error) {
console.error("Error fetching weather data:", error);
}
}
getWeatherData();
这里使用的是URL I m:https://api. openweathermap.org/data/2.5/one calls/timenchne?lat=${LATITUDE}&lon=${LONGITUDE}&dt=${Math. Floor(date.gettime()/1000)}&appid=${API_KEY}&units=imperial
。