Home > Google > Google ‘hidden’ weather API

Google ‘hidden’ weather API

April 23rd, 2010

Google has a ‘hidden’ API that lets you get the weather conditions for a specific city.

http://www.google.com/ig/api?weather={0}

Put your City name in place of {0}

I use C# to get a specific field and return my own value

      public string GetWeatherForCity()
      {
         string result = "";
         //string XML = ScreenScrape(string.Format("http://ws.geonames.org/findNearByWeatherXML?lat={0}&lng={1}", Lat, Long));
         string XML = ScreenScrape(string.Format("http://www.google.com/ig/api?weather={0}", city));
         XmlDocument xDoc = new XmlDocument();
         xDoc.LoadXml(XML);
         XmlElement xElement = xDoc.SelectSingleNode(@"/xml_api_reply/weather/current_conditions/condition") as XmlElement;

         if (xElement != null)
         {
            if (xElement.Attributes["data"].Value.ToLower().Contains("rain"))
            {
               result = "regenachtige";
            }

            if (xElement.Attributes["data"].Value.ToLower().Contains("sun"))
            {
               result = "zonnige";
            }

            if (xElement.Attributes["data"].Value.ToLower().Contains("cloud"))
            {
               result = "bewolkte";
            }
         }

         return result;
      }
Categories: Google Tags:
Comments are closed.