1

我目前有一段代码只显示给定邮政编码中的当前天气。有人可以帮助我获得 5 天的预测。这是我到目前为止所拥有的。

                        var loc = zipcode;
                    var u = 'f';

                    var query = "SELECT item.condition FROM weather.forecast WHERE location='" + loc + "' AND u='" + u + "'";
                    var cacheBuster = Math.floor((new Date().getTime()) / 1200 / 1000);
                    var url = '<http://query.yahooapis.com/v1/public/yql?q=>' + encodeURIComponent(query) + '&format=json&_nocache=' + cacheBuster;

                    window['wxCallback'] = function(data) {
                        var info = data.query.results.channel.item.condition;
                        $('#wxIcon').css({
                            backgroundPosition: '-' + (61 * info.code) + 'px 0'
                        }).attr({
                            title: info.text
                        });
                        $('#wxIcon2').append('<img src="<http://l.yimg.com/a/i/us/we/52/>' + info.code + '.gif" width="34" height="34" title="' + info.text + '" />');
                        $('#wxTemp').html(info.temp + '&deg;' + (u.toUpperCase()));
                    };

                    $.ajax({
                        url: url,
                        dataType: 'jsonp',
                        cache: true,
                        jsonpCallback: 'wxCallback'
                    });

这是 YQL 控制台。LINK 我找到了预测,但我不知道如何实现它。我对 YQL 很陌生……谢谢!

4

1 回答 1

0

我在这里发布了一个完整的示例 - https://gist.github.com/mvark/5231461

查看Yahoo Weather API文档以获取有关 API 的更多详细信息

于 2014-01-15T11:43:13.857 回答