I want to implement weather information which will show me results that depends on my longitude and latitude.
My app is getting coordinates from GPS so getting them is not a problem. Only thing is, I want to show some weather information for the city that is nearest me and that it has weather info.
Can you give me some ideas and solutions.
What do you think about google weather API?
How to make this to search for the nearest and how to give to this code lat and long.
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("<b>City : " + nodeList1.Item(0).SelectSingleNode("city").Attributes["data"].InnerText + "</b>");
XmlNodeList nodeList = root.SelectNodes("weather/current_conditions");
HttpContext.Current.Response.Write("
");
HttpContext.Current.Response.Write("
<table class="bordered" cellpadding="5">
<tbody><tr><td><b><big><nobr>" + nodeList.Item(0).SelectSingleNode("temp_c").Attributes["data"].InnerText + " °C | " + nodeList.Item(0).SelectSingleNode("temp_f").Attributes["data"].InnerText + " °F</nobr></big></b>");
HttpContext.Current.Response.Write("<b>Current:</b> " + nodeList.Item(0).SelectSingleNode("condition").Attributes["data"].InnerText + "");
HttpContext.Current.Response.Write("" + nodeList.Item(0).SelectSingleNode("wind_condition").Attributes["data"].InnerText + "");
HttpContext.Current.Response.Write(nodeList.Item(0).SelectSingleNode("humidity").Attributes["data"].InnerText);
nodeList = root.SelectNodes("descendant::weather/forecast_conditions");
foreach (XmlNode nod in nodeList)
{
HttpContext.Current.Response.Write("</td>
<td align="center">" + nod.SelectSingleNode("day_of_week").Attributes["data"].InnerText+ "");
HttpContext.Current.Response.Write("<img src="http://www.google.com" + nod.SelectSingleNode("icon").Attributes["data"].InnerText + "" alt="" + nod.SelectSingleNode("condition").Attributes["data"].InnerText + "">");
HttpContext.Current.Response.Write(nod.SelectSingleNode("low").Attributes["data"].InnerText + "°F | ");
HttpContext.Current.Response.Write(nod.SelectSingleNode("high").Attributes["data"].InnerText + "°F");
}
HttpContext.Current.Response.Write("</td>
</tr>
</tbody></table>
");
}
catch (System.Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
}
finally
{
GoogleResponse.Close();
}
}
I actually had a similar issue a while back.
I decided to go with Wunderground as I had too many issues with Google Weather. *Edit, I added a working google example below the wunderground one. The google api requires a city name or a zip code it seems.
Here is my example, pardon my sloppy code, typing this from memory.
Google example