Chinaunix首页 | 论坛 | 博客
  • 博客访问: 562233
  • 博文数量: 192
  • 博客积分: 3780
  • 博客等级: 中校
  • 技术积分: 1487
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-26 10:11
文章存档

2012年(6)

2011年(160)

2010年(26)

分类: 嵌入式

2011-04-29 22:48:22

实时股票和天气预报

实时股票

Google 的数据

1. 实时数据

2.K线图

3. 补全信息 "".

Yahoo 的数据

1. 实时数据

2. K线图

3. K线图数据

天气预报

Google Weather API 只支持美国地区使用邮政编码进行查询,例如: (94043 为 山景城, 美国加州 的邮政编码) 而除了美国以外的地区需要使用经纬度坐标作为参数才能执行 Google Weather API, 例如: (30670000,104019996 为 成都, 中国大陆 的经纬度坐标)

当然,也可能通行城市名称的汉语拼音来查询,例如:以下是北京的天气

要其它地区的经纬度坐标,可以通过 Google API 提供的国家代码列表及相应的城市经纬度坐标列表可以查询到,以下是 Google API 提供的查询参数: (查询 Google 所支持的所有国家的代码,并以 zh-cn 简体中文显示)

Google Weather API 只支持美国地区使用邮政编码进行查询,例如: (94043 为 山景城, 美国加州 的邮政编码) 而除了美国以外的地区需要使用经纬度坐标作为参数才能执行 Google Weather API, 例如: (30670000,104019996 为 成都, 中国大陆 的经纬度坐标)

当然,也可能通行城市名称的汉语拼音来查询,例如:以下是北京的天气

要其它地区的经纬度坐标,可以通过 Google API 提供的国家代码列表及相应的城市经纬度坐标列表可以查询到,以下是 Google API 提供的查询参数: (查询 Google 所支持的所有国家的代码,并以 zh-cn 简体中文显示)

C#范例:

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(@"").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; }

 } }

附:其它天气API

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

北京天气(可以通过搜索查找)

国内API:

北京天气

北京

阅读(969) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~