TechNomad

Traveling the World in an Attempt to Share Experiences
Home Login | Subscribe Latest Entries

Weather API

1 Dec 2009

  1. Programming
<Dec 2009>
S M T W T F S
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

Thank You Google

Day's Slideshow

I love Google. Their MapAPI works great for my purposes, though I have yet utilised it as well I would have like...
Anyhow, this post is about their weather forcasting. I have been using their site to search "weather Masan Korea" to see the local weather for today and the upcoming few days.
A little search online found that Google does make their weather information available through simple XML at http://www.google.com/ig/api?weather=Masan-si,%20Korea and then you just need to parse the data. I chose PHP.
<div><div style="text-align: center; font-size: 1.2em"> <b>Weather in <u>Masan Korea</u></b></div> <?php // Load Google's XML file $weather = @simplexml_load_file("http://www.google.com/ig/api?weather=Masan-si,%20Korea"); // Collect Data for each forcasted day (which tends to include today plus three days) foreach ($weather->weather->forecast_conditions as $for) { // Best use float:left instead of a table :) echo '<div style="float: left; text-align: left; padding: 1px">'; // The day of the week echo "\t<div style=\"text-align: center\">{$for->day_of_week['data']}</div>\n"; // Google's Pic of the Weather echo "\t<div style=\"text-align: center\"><img "; echo "src=\"http://www.google.com{$for->icon['data']}\" "; echo "alt=\"{$for->condition['data']}\" /></div>\n"; // The day's high temp in both Fahrenheit and Celcius echo "\t<div>{$for->high['data']}°F / " . round(($for->high['data'] - 32) * 5 / 9, 1) . "°C</div>\n"; // The day's low temp in both Fahrenheit and Celcius echo "\t<div>{$for->low['data']}°F / " . round(($for->low['data'] - 32) * 5 / 9, 1) . "°C</div>\n"; echo "</div>\n"; } ?></div>
You can see my use of the box on my home page
Order PrintsHide EntryPost a Comment ShareThis
<< 29 Nov 2009 Dec 2009 5 Dec 2009 >>