当前位置: 代码迷 >> Web前端 >> 运用Google Weather API查询天气预报
  详细解决方案

运用Google Weather API查询天气预报

热度:126   发布时间:2012-11-20 09:55:43.0
使用Google Weather API查询天气预报


1、使用邮政编码进行查询(美国地区)
例如:
????
http://www.google.com/ig/api?hl=zh-cn&weather=94043
???? (94043 为 山景城, 美国加州 的邮政编码)

2、使用经纬度坐标作为参数才能执行 Google Weather API
?例如:
???
http://www.google.com/ig/api?hl=zh-cn&weather=,,,30670000,104019996
??? (30670000,104019996 为 成都, 中国大陆 的经纬度坐标)

3、通行城市名称的汉语拼音来查询
例如:
?????
http://www.google.com/ig/api?hl=zh-cn&weather=Beijing(北京的天气)

?
要其它地区的经纬度坐标,可以通过 Google API 提供的国家代码列表及相应的城市经纬度坐标列表可以查询到,以下是 Google API 提供的查询参数:
http://www.google.com/ig/countries?output=xml&hl=zh-cn
(查询 Google 所支持的所有国家的代码,并以 zh-cn 简体中文显示)
http://www.google.com/ig/cities?output=xml&hl=zh-cn&country=cn
http://www.google.com/ig/cities?country=cn

缺省返回的是英文, 可以增加一个参数来返回中文:
http://www.google.com/ig/api?weather=Nanjing&hl=zh-cn

取得中国的所有城市代码:
http://www.google.com/ig/cities?country=cn

缺省返回是 JSON 格式.增加一个参数返回XML格式(不支持Firefox)
http://www.google.com/ig/cities?country=cn&output=xml

  相关解决方案