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

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

他们提供数据,如何显示由你决定。你需要解析结果来管理自己的图像显示。 - charlietfl
请告诉我结果中的背景图片在哪里?我不相信它们存在。 - triplethreat77
2个回答

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接