Android项目中接入百度天气的方法

首先要拿到的自己的key和安全码

没有的key以的申请地址:http://lbsyun.baidu.com/apiconsole/key

安全码在:创建应用时输入的安全码。


以上参数都有的了就可以进行申请了,GET请求,完整的URL地址:

http://api.map.baidu.com/telematics/v3/weather?location="+ loction+ "&output=json&ak=K4yvk2NfsqL0yCiyrxvmyVDl&mcode=" + mocde

loction:城市名称,经过编码处理后添加到URL里使用,否则无效。

mocde:完整安全码


注意:城市名称必须经过编码处理后才能添加到的URL里使用。

返回的参数格式:

{
    "error": 0,
    "status": "success",
    "date": "2015-03-11",
    "results": [
        {
            "currentCity": "厦门",
            "pm25": "30",
            "index": [
                {
                    "title": "穿衣",
                    "zs": "较冷",
                    "tipt": "穿衣指数",
                    "des": "建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。"
                },
                {
                    "title": "洗车",
                    "zs": "不宜",
                    "tipt": "洗车指数",
                    "des": "不宜洗车,未来24小时内有雨,如果在此期间洗车,雨水和路上的泥水可能会再次弄脏您的爱车。"
                },
                {
                    "title": "旅游",
                    "zs": "适宜",
                    "tipt": "旅游指数",
                    "des": "温度适宜,又有较弱降水和微风作伴,会给您的旅行带来意想不到的景象,适宜旅游,可不要错过机会呦!"
                },
                {
                    "title": "感冒",
                    "zs": "易发",
                    "tipt": "感冒指数",
                    "des": "天冷空气湿度大,易发生感冒,请注意适当增加衣服,加强自我防护避免感冒。"
                },
                {
                    "title": "运动",
                    "zs": "较不宜",
                    "tipt": "运动指数",
                    "des": "有降水,推荐您在室内进行各种健身休闲运动,若坚持户外运动,须注意保暖并携带雨具。"
                },
                {
                    "title": "紫外线强度",
                    "zs": "最弱",
                    "tipt": "紫外线强度指数",
                    "des": "属弱紫外线辐射天气,无需特别防护。若长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。"
                }
            ],
            "weather_data": [
                {
                    "date": "周三 03月11日 (实时:10℃)",
                    "dayPictureUrl": "http://api.map.baidu.com/images/weather/day/xiaoyu.png",
                    "nightPictureUrl": "http://api.map.baidu.com/images/weather/night/xiaoyu.png",
                    "weather": "小雨",
                    "wind": "微风",
                    "temperature": "13 ~ 10℃"
                },
                {
                    "date": "周四",
                    "dayPictureUrl": "http://api.map.baidu.com/images/weather/day/zhenyu.png",
                    "nightPictureUrl": "http://api.map.baidu.com/images/weather/night/duoyun.png",
                    "weather": "阵雨转多云",
                    "wind": "微风",
                    "temperature": "14 ~ 9℃"
                },
                {
                    "date": "周五",
                    "dayPictureUrl": "http://api.map.baidu.com/images/weather/day/duoyun.png",
                    "nightPictureUrl": "http://api.map.baidu.com/images/weather/night/duoyun.png",
                    "weather": "多云",
                    "wind": "微风",
                    "temperature": "22 ~ 11℃"
                },
                {
                    "date": "周六",
                    "dayPictureUrl": "http://api.map.baidu.com/images/weather/day/duoyun.png",
                    "nightPictureUrl": "http://api.map.baidu.com/images/weather/night/duoyun.png",
                    "weather": "多云",
                    "wind": "微风",
                    "temperature": "23 ~ 14℃"
                }
            ]
        }
    ]
}


然后自行根据需要解析对应的数据即可!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值