Use Google weather API to query weather forecasts

Source: Internet
Author: User
Use Google weather API to query weather forecasts

Google weather API only supports querying by zip code in the United States. For example:
Http://www.google.com/ig/api? Hl = ZH-CN & weather = 94043
(94043 is the zip code of Mountain View city, California, USA)

In addition to the United States, you must use latitude and longitude coordinates as parameters to execute the Google weather API. For example:
Http://www.google.com/ig/api? Hl = ZH-CN & weather =, 3067133, 104019996
(3067213,10409706 is the longitude and latitude coordinates of Chengdu and mainland China)

Of course, you may also query the city name in Chinese pinyin. For example, the following is the weather in Beijing.
Http://www.google.com/ig/api? Hl = ZH-CN & weather = Beijing

To coordinate the longitude and latitude of other regions, you can use the countries provided by Google APICodeYou can query the list and corresponding city longitude and latitude coordinates. The following are the query parameters provided by Google API:
Http://www.google.com/ig/countries? Output = xml & HL = ZH-CN

(Query the code of all countries supported by Google and display it in ZH-CN Simplified Chinese)
Http://www.google.com/ig/cities? Output = xml & HL = ZH-CN & Country = Cn

C # example:

Using system;

Using system. Collections. Generic;

Using system. text;

Using system. xml;

Using system. net;

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;

}

}

}

Appendix: other weather APIs

Yahoo: http://developer.yahoo.com/weather/

Beijing weather (you can search for it)

Http://xml.weather.yahoo.com/forecastrss? P = chxx0008 & U = f

Domestic API:

Weather in Beijing

Http://weather.all2rss.com/weatherrss.asp? City = Beijing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.