简体   繁体   English

Yahoo Weather API 3天的湿度值预报

[英]Yahoo Weather API 3 days Forecast with humidity value

I am building a web app, which uses Yahoo Weather API to provide weather information, based on a ZIP code, provided by the users. 我正在构建一个Web应用程序,该应用程序使用Yahoo Weather API根据用户提供的邮政编码提供天气信息。

I know that in order to obtain this data for certain number of days I have to add it as a parameter in my request, like so: 我知道,为了获得一定天数的数据,我必须将其作为参数添加到请求中,如下所示:

http://weather.yahooapis.com/forecastrss?p=33035&u=c&d=3

Which gives this result: 得到以下结果:

<channel>
....
<yweather:location city="Homestead" region="FL" country="US"/>
<yweather:units temperature="C" distance="km" pressure="mb" speed="km/h"/>
<yweather:wind chill="19" direction="90" speed="11.27"/>
<yweather:atmosphere humidity="78" visibility="16.09" pressure="1021" rising="1"/>
<yweather:astronomy sunrise="7:12 am" sunset="7:36 pm"/>
...
<item>
...
<yweather:forecast day="Wed" date="2 Apr 2014" low="19" high="28" text="Mostly Sunny" code="34"/>
<yweather:forecast day="Thu" date="3 Apr 2014" low="21" high="29" text="Partly Cloudy" code="30"/>
<yweather:forecast day="Fri" date="4 Apr 2014" low="20" high="28" text="Partly Cloudy" code="30"/>
<guid isPermaLink="false">USFL0208_2014_04_04_7_00_EDT</guid>
</item>
</channel>

However I need to be able to get the humidity level for EVERY day in the forecast and not just the current one. 不过,我需要能够得到每天的预测,而不仅仅是当前的湿度水平。 I've tried to find solution here and also read the Yahoo API documentation, but it's really a short one. 我试图在这里找到解决方案,并阅读Yahoo API文档,但这确实很短。

I've also tried http://www.myweather2.com/ and http://developer.worldweatheronline.com/ , but they have the same issue with humidity - it's shown only for the current day and stripped from the whole forecast. 我还尝试了http://www.myweather2.com/http://developer.worldweatheronline.com/ ,但是它们在湿度方面存在相同的问题-仅在当天显示,并且从整个预测中删除。

I'll keep trying with other free Weather APIs, but if you can help here I'd be very grateful. 我将继续尝试其他免费的Weather API,但是如果您能在这里提供帮助,我将非常感激。

I've spent some time researching for better APIs than the Yahoo! 我花了一些时间研究比Yahoo!更好的API。 Weather API and I found something, that works for me, so I've decided to share the info, in case anyone else bump into this some day. Weather API,我发现了一些对我有用的东西,所以我决定共享此信息,以防万一有人碰到这一天。

Version 2 of the Forecast API looks like a nice solution, because it provides detailed information, more specifically the humidity index for each day in the forecast, which was what I was looking for in the first place. Forecast API的第2版​​看起来是一个不错的解决方案,因为它提供了详细的信息,更具体地说是天气预报中每天的湿度指数,这正是我最初要寻找的。 There are also number of libraries for this API (languages include PHP, Node.js, Python, Perl and others). 该API也有许多库(语言包括PHP,Node.js,Python,Perl等)。

It works with longitude & latitude as in this example 如本例所示,它可以在经度和纬度下工作

https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE,TIME

and of course one needs to register for an API key. 当然,需要注册一个API密钥。
The TIME parameter is optional, the temperature uses Fahrenheit metrics by default, but this can be changed with additional ?units=ca parameter. TIME参数是可选的,默认情况下温度使用华氏度,但是可以通过其他?units=ca参数进行更改。

One disadvantage is that you get only a 1,000 free calls per day, which probably won't be suitable for big applications. 缺点是每天只能打1,000个免费电话,这可能不适合大型应用程序。

If you know a better answer to the original question, I'll be very happy to hear it. 如果您对原始问题有更好的答案,我会很高兴听到。 Until then I'll use this solution, without going into much details: 在此之前,我将使用此解决方案,而无需赘述:

// The default result from a Forecast API call is in JSON,
// so decode it to an object for easier access
$fcObj = json_decode($jsonResult);

if(!empty($fcObj->daily->data[0]->humidity)) {

    // get humidity value in %
    $humidty = $fcObj->daily->data[0]->humidity * 100;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM