非常好的强大的jquery天气实现与用户的饲料位置

时间:2011-02-02 01:03:23

标签: jquery yahoo-weather-api

嘿,我已经搜遍了整个地方,无法真正下定决心。我安装了一个天气小部件,可以将天气从雅虎服务器上拉下来,但我无法弄清楚如何做一些事情。成功地从DAY切换到NIGHT图像,没有任何破解。而且我也不确定如何拉出5天的预报。

这就是我正在使用的:

    $.YQL = function(query, callback) {
        var encodedQuery = encodeURIComponent(query.toLowerCase()),
        url = 'http://query.yahooapis.com/v1/public/yql?q=' + encodedQuery + '&format=json&callback=?';
        $.getJSON(url, callback);
    };

    $.YQL("SELECT * FROM weather.forecast WHERE location = 93065", function(data){
        var w = data.query.results.channel;

        var d = new Date();
        var curr_hour = d.getHours();
        var dn = (curr_hour < 18 && curr_hour > 4 ? 'd' : 'n');

        var weatherImage = "http://l.yimg.com/a/i/us/nws/weather/gr/" + w.item.condition.code + dn + ".png";
        var weatherIcon  = "http://l.yimg.com/a/i/us/nws/weather/gr/" + w.item.condition.code + "s.png";
        $('.weatherImage').html("<img src='" + weatherImage + "' />");
        $('.weatherTemp').html(w.item.condition.temp + "&deg;");
        $('.weatherText').html(w.item.condition.text);

        $(this).everyTime('300s', function(){
            var w = data.query.results.channel;
            var d = new Date();
            var curr_hour = d.getHours();
            var dn = (curr_hour < 18 && curr_hour > 4 ? 'd' : 'n');

            var weatherImage = "http://l.yimg.com/a/i/us/nws/weather/gr/" + w.item.condition.code + dn + ".png";
            var weatherIcon  = "http://l.yimg.com/a/i/us/nws/weather/gr/" + w.item.condition.code + "s.png";
            $('.weatherImage').html("<img src='" + weatherImage + "' />");
            $('.weatherTemp').html(w.item.condition.temp + "&deg;");
            $('.weatherText').html(w.item.condition.text);
        });
    }).appendTo('.pin-up-weather');

不漂亮,但它是一个短期解决方案。有没有人有定制的天气预报的经验,非常动态?

我希望根据用户浏览的位置更新天气,但我不可能。我看了Googles geolocation API,但是已经不再使用了map api接管的东西,但是我仍然无法解决这个问题。

如果不是我可以让脚本从数据库中获取位置,具体取决于用户在其配置文件中指定的位置。

感谢

1 个答案:

答案 0 :(得分:0)

一个迟到的答案,但我刚刚遇到了jQuery插件simpleWeather

似乎很直接。

相关问题