English 中文(简体)
能否在开放式批量中获取过去的降水数据?
原标题:Is there a way to get past precipitation data in OpenWeatherMap API?

采用开放式天气预报系统(一个信号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

最佳回答

The data returned by the One Call API 3.0 (for historical data) returns two sub-fields with precipitation data:

  • data.rain
  • data.snow

每个领域都有一个阵列,每个小时的降水率(mm/hr)。

If these sub-fields are missing, that means there was no precipitation:

如果你看不到您的APIC对策中的某些参数,那么就意味着这些天气现象在所选择的城市或地点测量时并不存在。 只有实际测量或计算的数据才能在APIC的回复中显示。


Note this answer is for One Call API 3.0. According to this migration guide, API 2.5 had the data, but in slightly different fields: current.rain and current.snow. (API 2.5 will be shut down June 2024.)

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签