好记性不如铅笔头

android, 编程

Android应用开发笔记:获取天气信息

通过发送【 Http 】请求,我们可以获得天气情况。一般我们获取中国城市的天气都是从【 中国天气网 】获得的。中国天气网的接口并没有详细的文档说明,通过查询网络,得到的一般接口如下:

以南京为例,

1)【 http://www.weather.com.cn/data/cityinfo/101190101.html 】

返回:

{“weatherinfo”:{“city”:”南京”,”cityid”:”101190101″,”temp1″:”20℃”,”temp2″:”10℃”,”weather”:”晴转多云”,”img1″:”d0.gif”,”img2″:”n1.gif”,”ptime”:”11:00″}}

2)【 http://www.weather.com.cn/data/sk/101190101.html 】

返回:

{“weatherinfo”:{“city”:”南京”,”cityid”:”101190101″,”temp”:”19″,”WD”:”东南风”,”WS”:”2级”,”SD”:”33%”,”WSE”:”2″,”time”:”13:45″,”isRadar”:”1″,”Radar”:”JC_RADAR_AZ9250_JB”}}

3)【 http://m.weather.com.cn/data/101190101.html 】

返回:

{“weatherinfo”。。。。。。。。。。。。。。。。。。。。”}}

4)默认天气图标:

http://www.weather.com.cn/static/html/legend.shtml 】

备注:

1)一般来讲,第1,2个连接返回的信息足够使用了,第3个返回的很多。

2)查询城市编码有好多方法,可以参考【 http://blog.csdn.net/lzqwebsoft/article/details/7054045 】

发表评论

15 − 13 =

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据