really good robust jquery weather implementation with user location for feeds
Hey, I have searched all over the place and can't really make up my mind. I have a weather widget installed that pulls weather off yahoo servers but i can't figure out how to do a few things. Successfully switch from DAY to NIGHT images automatically without some sort of hack. and I'm not sure how to pull a 5-day forcast either.
This is what I'm using:
$.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.cond开发者_如何学Pythonition.temp + "°");
$('.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 + "°");
$('.weatherText').html(w.item.condition.text);
});
}).appendTo('.pin-up-weather');
not pretty, but its a short term solution. Has anyone had experience with custom made weather feeds that work pretty dynamically?
I wanted to have the weather just update based on where the user is browsing from but I don't thats possible. I looked at Googles geolocation API but there are no longer in service, things that the maps api took over, but i still wasn't able to figure it out.
if not i'm fine with having the script grab the location from a database depending on what user specifies in their profile.
thanks
A late answer but I just came across the jQuery plugin simpleWeather.
It seems to be straight forward.
精彩评论