雅虎天气API 3天湿度值预测

问题描述:

我正在构建一个网络应用程序,该应用程序使用Yahoo Weather API根据用户提供的邮政编码提供天气信息。雅虎天气API 3天湿度值预测

我知道,为了得到这个数据一定的天数我必须将它添加在我的请求中的参数,像这样:

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

哪个给出了这样的结果:

<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> 

但是我需要能够在预测中获得每日天的湿度水平,而不仅仅是当前的一天。我试图在这里找到解决方案,并阅读雅虎API文档,但它确实很短。

我也尝试过http://www.myweather2.com/http://developer.worldweatheronline.com/,但它们与湿度有相同的问题 - 仅在当天显示,并从整个预测中剥离。

我会继续尝试与其他免费的天气API,但如果你能在这里帮助,我会非常感激。

我花了一些时间研究更好的API比雅虎!天气API和我发现了一些东西,这对我很有用,所以我决定分享这些信息,以防其他人在某天遇到这种情况。

Forecast API的第2版看起来是一个不错的解决方案,因为它提供了详细的信息,更具体地说是预测中每天的湿度指数,这正是我一直在寻找的。 这个API也有很多库(语言包括PHP,Node.js,Python,Perl等)。

它与经度纬度&在这个例子中

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

,当然还有一个需要API密钥注册。
时间参数是可选的,默认情况下温度使用华氏度量,但可以通过额外的?units=ca参数进行更改。

一个缺点是,你每天只能获得1000个免费电话,这可能不适合大型应用。

如果你对原始问题有更好的回答,我会很乐意听到它。在此之前,我将使用此解决方案,而不会涉及太多细节:

// 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; 

}