Getting Weather from Weather.gov using Javascript and JQuery

I had a simple task to get a 7 day forecast of the high and low temperatures. To start off with, I looked at a number of sources to get this information from. Here is a good discussion about weather APIs, mostly geared toward iPhone.

I decided to go with the NOAA Rest service, and get the data from Weather.gov.

Also, I ended up publishing it on Github if you want the full source.

The first step I did was use jQuery to hit the NOAA URI with the appropriate parameters:

$.get('http://graphical.weather.gov/xml/SOAP_server/ndfdXMLclient.php?whichClient=NDFDgenMultiZipCode&zipCodeList=' + zip +'&product=time-series&maxt=maxt&mint=mint&Submit=Submit'

This would return a huge XML structure which then needs to be parsed.

// Parse the XML response to get out the values we want
$(xml).find('temperature').each()
...
// Iterate over the day values and assigne to the right array
$(this).find('value').each(function(){
array[count] = $(this).text();
count = count + 1;
});

I guess the overall takeaway is that the NOAA provides a free interface to getting facts about the weather, though it seems like that interface may have been designed a while back, since it is a little cumbersome to use.

If you want more data than just the highs and lows for temperature, check out this website which shows you all the different options you can query for.

Tagged , ,

One thought on “Getting Weather from Weather.gov using Javascript and JQuery

  1. Kavit says:

    I am getting this error in the console, when trying to click on the submit button – ” No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘null’ is therefore not allowed access.”
    Please help me out ….

    Thank Your Sir,
    -Kavit

Leave a Reply

Your email address will not be published. Required fields are marked *