如何从API获取Yahoo天气背景?

问题描述 投票:3回答:3

我有一个天气小部件,我需要动态背景。雅虎有天气API,但是我找不到与天气类型相关的背景图片。 https://weather.yahoo.com/这可能吗?

var url = 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20location%3D%2248907%22&format=json'
            $.getJSON(url, function (data) {
                console.log(data)
            })
javascript jquery json yahoo-api yahoo-weather-api
3个回答
3
投票

API不提供任何图像,但是您可以使用大量数据自行提供图像。例如,使用以下属性

condition":{"code":"34", ...  // here you can bind an image to the code

然后您有了风对象

wind":{
  "chill":"55",       // thermometer?
  "direction":"0",     // use an image or a canvas to draw an arrow dynamically
  "speed":"0"
}, ...

和大气物体

"atmosphere":{
  "humidity":"51",     // some drops?
  "pressure":"30.4",   // textual..
  "rising":"2",
  "visibility":"10"    // textual..
}, ...

依此类推。如您所见,有很多方法可以说明这些数据,但是如何操作完全取决于您。


1
投票

抱歉,目前没有API。但是您可以通过在浏览器开发人员工具上查看网络活动来访问其背景。

最好的解决方案是用自己的图像构建自己的Api,

这是其中的背景网址示例:

https://s.yimg.com/os/mit/media/m/weather/images/fallbacks/lead/clear_n-e618500.jpg


0
投票

是的,我遇到了同样的问题。只是将我自己的自定义图像与基于天气类型的if / else语句一起使用,但是不得不像这样写出所有可能性是很痛苦的。不敢相信他们不会费心在结果数据中添加它。

© www.soinside.com 2019 - 2024. All rights reserved.