首页 文章

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

提问于
浏览
1

我正在构建一个Web应用程序,它使用Yahoo Weather API根据用户提供的邮政编码提供天气信息 .

我知道为了获取特定天数的数据,我必须在请求中将其添加为参数,如下所示:

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>

但是我需要能够在预测中获得 EVERY 天的湿度水平,而不仅仅是当前的湿度水平 . 我真是个短暂的人 .

我也尝试了http://www.myweather2.com/http://developer.worldweatheronline.com/,但它们在湿度问题上也有同样的问题 - 它仅在当天显示并且从整个预测中脱离出来 .

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

1 回答

  • 1

    我花了一些时间研究比Yahoo!更好的API . Weather API和我发现了一些对我有用的东西,所以我决定分享这些信息,以防有人在某一天遇到这个问题 .

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

    它适用于此示例中的经度和纬度

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

    当然,需要注册API密钥 .
    TIME 参数是可选的,默认情况下温度使用华氏度指标,但可以使用额外的 ?units=ca 参数进行更改 .

    一个缺点是每天只能获得1,000次免费通话,这可能不适合大型应用 .

    如果您对原始问题有更好的答案,我会很高兴听到它 . 在那之前我将使用这个解决方案,而不需要详细介绍:

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

相关问题