Get Weather Data for your website!!

May 30th, 2012 by admin Leave a reply »

I have been looking at a few options on how to get live weather data for the web and I came across the Weather Underground’s weather API found HERE.  I have posted the code snippet below that will populate the divs with the according weather data using JQuery, I left out my API key for obvious reasons, but you can get a free one my following my link above and registering as a developer, enjoy!

$.ajax({
                url: "http://api.wunderground.com/api/<Your API Key>/geolookup/conditions/q/KY/Murray.json",
                dataType: "jsonp",
                success: function (parsed_json) {
                    $("#tempValue").val(parsed_json['current_observation']['temp_f']);
                    $('#skyCondValue').append($('<option>', { value: "skyCond" }).text(parsed_json['current_observation']['weather']));
                    $('#humidValue').val(parsed_json['current_observation']['dewpoint_f']);
                    $("#windSpeedVal").val(parsed_json['current_observation']['wind_mph']);
                    $("#windDirVal").append($('<option>', { value: "windDir" }).text(parsed_json['current_observation']['wind_dir']));
                    $('#envInfo').text(parsed_json['current_observation']['temp_f'] + " " + parsed_json['current_observation']['weather'] + " " + parsed_json['current_observation']['dewpoint_f'] + " " +
                    parsed_json['current_observation']['wind_mph'] + " " + parsed_json['current_observation']['wind_dir']);
                }
            });

Advertisement

Leave a Reply