July 25, 2007

Google Weather API


Please go to http://www.codeplex.com/awAPI the project and documentation is there.
/Roman

This is a little guide on how to use the Google Weather API

Use this XML file for output in Fahrenheit:
http://www.google.com/ig/api?weather=Drammen
And this one for Celsius:
http://www.google.co.uk/ig/api?weather=Drammen

And here is the sample C# parser (Celsius Version):

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Net;

///Code by Roman Alifanov - API by Google
///Posted on http://animaonline.blogspot.com
namespace GoogleWeatherAPI_Parser
{
class Program
{
static void Main(string[] args)
{
int i = 0;
XmlNodeList GWP_NodeList = GoogleWeatherAPI_Parser(@"http://www.google.co.uk/ig/api?weather=Drammen").SelectNodes("xml_api_reply/weather/current_conditions");
Console.WriteLine("Current weather in Drammen: " + GWP_NodeList.Item(i).SelectSingleNode("temp_c").Attributes["data"].InnerText);
Console.ReadLine();
}
private static XmlDocument GoogleWeatherAPI_Parser(string baseUrl)
{
HttpWebRequest GWP_Request;
HttpWebResponse GWP_Response = null;
XmlDocument GWP_XMLdoc = null;
try
{
GWP_Request = (HttpWebRequest)WebRequest.Create(string.Format(baseUrl));
GWP_Request.UserAgent = @"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4";
GWP_Response = (HttpWebResponse)GWP_Request.GetResponse();
GWP_XMLdoc = new XmlDocument();
GWP_XMLdoc.Load(GWP_Response.GetResponseStream());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
GWP_Response.Close();
return GWP_XMLdoc;
}
}
}
Enjoy :P


Back to Home

32 comments:

  1. Респект за пост и привет от мурманска

    ReplyDelete
  2. Thank you for valuable information.

    by,
    http://www.a2zinterviewquestions.com
    http://mygadgetguru.blogspot.com

    ReplyDelete
  3. Is it possible for between dates and enter city name or zip code.


    by,
    http://www.a2zinterviewquestions.com
    http://mygadgetguru.blogspot.com

    ReplyDelete
  4. Hello,
    why
    latitude_e6
    longitude_e6

    are empty?

    Thanks
    Andrea

    ReplyDelete
  5. I'm afraid this function is not fully implemented by Google, however you can use this GeoCoder (http://blog.donnfelker.com/2007/03/13/CGoogleGeocodeLatitudeAndLongitudeClass.aspx)
    to get the coordinates of a city

    Sample Source:
    cord = GoogleGeocoder.Geocode.GetCoordinates("Drammen");
    string MapUrl = @"http://maps.google.com/maps?ie=UTF8&ll=" + cord.Latitude +"," + cord.Longitude +"&spn=2.589805,5.141602&z=12";

    ReplyDelete
  6. Please, feel free to contact me if you encounter any problems :)

    - Roman

    ReplyDelete
  7. you can using yahoo weather also
    api etc!

    ReplyDelete
  8. Very good tip.
    Congratulation.
    I think i will'use it on this Travel in Tuscany Website

    ReplyDelete
  9. Does anyone know where the offical google doc is on this?

    ReplyDelete
  10. I don't think that there are any official google docs on that

    ReplyDelete
  11. can anyone send me a sample files which can access google infomation?
    I really appreciate your help. I need it urgently.
    Thank you again.

    ReplyDelete
  12. my email is:
    itbird@gmail.com

    ReplyDelete
  13. Have you tried reading through the post? The code is there. :)
    You may find this interesting too
    http://codeplex.com/awapi
    /Roman
    Please contact me directly if you need any help.

    ReplyDelete
  14. Hi.
    Just wondering if the code needs the line with GWP_Request.UserAgent...

    ReplyDelete
  15. Nope, It now doesn't
    Please go to
    http://codeplex.com/aWAPI
    I will be releasing version 2.1 soon :)

    ReplyDelete
  16. Hi.

    I wanted to ask, the frequency the measurements are taken. I ve checked the measurements against those from freemeteo.com and they are slightly different. The time that the XML shows is Greenwich time ?

    ReplyDelete
  17. Hello! Well it seems like the "current_date_time" is in GMT, I'm not sure however, but I'll see what I can find out about it :)

    "Please go to
    http://codeplex.com/aWAPI
    I will be releasing version 2.1 soon :)"

    ReplyDelete
  18. I am mostly interest about the frequency of the measurements. I mean, I will probably want to find the weather conditions in an interval of +/- 30 min. So, if measurements have been taken like 2 hours before, that won't be quite good, at least for me :) .

    ReplyDelete
  19. It's Reallly good, i got what i want to find that how can include google weather in our page. Great dude....

    ReplyDelete
  20. I gathered more info as well regarding the google weather API and posted it on my site.

    Google weather api in flash and PHP

    It's basically a PHP back end proxy that feeds a flash client app. Now that the back stuff works I will now be working on cleaning up the client interface :)

    ReplyDelete
  21. A real time saver!!!

    The smack down on simple weather.

    Thanks again dude.

    ReplyDelete
  22. Here is one site developed with google weather api <a href="http://www.myhelmi.com/weather/current_weather.jsp?city=London,%20England>London Weather</a>

    ReplyDelete
  23. It seems google.co.uk is now giving American units, not standard ones. So you'll have to convert the temperatures to celsius yourself (or make 2 requests, one to google.com for the descriptions and one to google.fr for the temperatures).

    ReplyDelete
  24. You can also just pass a language parameter to the call:

    http://www.google.com/ig/api?weather=Drammen&hl=en-gb

    (en-gb being the lang code for the UK)

    ReplyDelete
  25. The google API works well for the US and major international cities, but what about not-so-well-known areas?

    I've been trying to get the API to work for El Calafate, Argentina, even tried the LAT/LONG version and nothing comes up.

    Does anyone know if I am doing something wrong?

    http://www.google.com/ig/api?weather=,,,-50333330,-72283333

    ReplyDelete
  26. I think We should multiply that by 1,000,000.
    In my case, This number, 1,000,000, helps me.

    ReplyDelete
  27. does this work on android? How do u import the API?

    ReplyDelete
  28. I recently develop a weather page with geolocalitation (HTML5), try this api:
    http://www.theweathernow.net/api/
    it uses the google weather api.

    ReplyDelete
  29. I am now not sure where you are getting your info, however good topic.
    I must spend some time finding out more or working out more.

    Thanks for excellent information I was looking for this info for my mission.


    Here is my webpage achat vues youtube
    my site :: plus de vue sur youtube

    ReplyDelete
  30. Excellent goods from you, man. I have understand your stuff previous to and
    you are just extremely fantastic. I really like what you've acquired here, certainly like what you're saying and the way in which
    you say it. You make it entertaining and you still take care
    of to keep it sensible. I can't wait to read much more from you. This is actually a wonderful site.

    Here is my homepage - acheter follower
    Also see my web site: acheter tweet

    ReplyDelete
  31. My spouse and I stumbled over here from a different web page and thought I may as well check things out.
    I like what I see so now i'm following you. Look forward to checking out your web page repeatedly.

    Feel free to surf to my blog ... acheter des followers

    ReplyDelete

Note: Only a member of this blog may post a comment.