PDA

View Full Version : Weather widgets


cocoonfx
07-24-2010, 03:45 PM
Hi Chaps


I am trying to find a weather widget which can be resizable. Ideally a widget which is like 60 x 60 pxs as I don't have much space.

Any ideas?

davidj
07-27-2010, 11:01 AM
why not write your own using googles weather API

Just throw a city at it

http://www.google.com/ig/api?weather=newcastle+upon+tyne

just need to parse the xml response

davidj
07-27-2010, 04:04 PM
Had some time on my hands (quite rare these days)

here is a little parser I knocked up which pulls out the icon image path from the google weather XML response

you can either replicate the path structure and use your own images or you could use a switch to remap the paths altogether

<?php

//Name of your place
$place="newcastle+upon+tyne";

//Initialize CURL
$curl = curl_init();

$timeout = 0;

//Set CURL options
curl_setopt ($curl, CURLOPT_URL, 'http://www.google.com/ig/api?weather='.$place.'&hl=en');
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout);

$xml_str=curl_exec($curl);

//close CURL
curl_close($curl);

// Parse the XML response
$xml = new SimplexmlElement($xml_str);

$icons = array();

foreach($xml->weather as $item) {

foreach($item->forecast_conditions as $new) {

$icons[] = $new->icon['data'];
}
}

///////////////////////////////
// output array of image paths (debug use only)
echo "<pre>";
print_r($icons);
echo "</pre>";
///////////////////////////////

?>

Corrosive
07-27-2010, 05:23 PM
Could you use the Google geolocator to output the user's location and feed it into $place?

davidj
07-27-2010, 08:15 PM
Yes of course

I have used this on a site before

http://www.maxmind.com/app/city

Never looked at the google solution

davidj
07-27-2010, 08:26 PM
A nice set of icons/sprite you could use with it... here (http://www.istockphoto.com/file_thumbview_approve/5872384/2/istockphoto_5872384-weather-icons-color.jpg)