Google Weather Provides weather information from the world. They accepts a wide range of parameters like [city],[country] e.g. London,England – or postcodes, ISO country codes (UK,DE etc.), Lat/long.
To integrate it with asp.net just use below function and it will return weather information for current and next 4 days with images according to weather.
public static void GoogleWeather(string location)
{
HttpWebRequest GoogleRequest;
HttpWebResponse GoogleResponse = null;
XmlDocument GoogleXMLdoc = null;
try
{
GoogleRequest = (HttpWebRequest)WebRequest.Create("http://www.google.com/ig/api?weather=" + string.Format(location));
GoogleResponse = (HttpWebResponse)GoogleRequest.GetResponse();
GoogleXMLdoc = new XmlDocument();
GoogleXMLdoc.Load(GoogleResponse.GetResponseStream());
XmlNode root = GoogleXMLdoc.DocumentElement;
XmlNodeList nodeList1 = root.SelectNodes("weather/forecast_information");
HttpContext.Current.Response.Write("City : " + nodeList1.Item(0).SelectSingleNode("city").Attributes["data"].InnerText + "");
XmlNodeList nodeList = root.SelectNodes("weather/current_conditions");
HttpContext.Current.Response.Write("
| " + nod.SelectSingleNode("day_of_week").Attributes["data"].InnerText + "");
HttpContext.Current.Response.Write(" |
Download : Download
Satheesh
February 24, 2010 at 11:49 am
Hi,
The code is not working if we give the ISO country code. I tried UK and it returned error as “Object reference not set to an instance…”.
Regards,
Satheesh
admin
February 24, 2010 at 1:56 pm
It will not work if we give country code or even full country name alone as weather will different in different cities in a country. You can use country code in conjunction with [city, country code] or [postcode,countrycode]