百度提供天气预报查询接口API,可以根据经纬度/城市名查询天气情况,我们可以在微信公众平台开发中调用这一接口。

接口说明

根据经纬度/城市名查询天气的结果

接口示例

http://api.map.baidu.com/telematics/v3/weather?location=北京&output=json&ak=6tYzTvGZSOpYB5Oc2YGGOKt8

http://lbsyun.baidu.com/apiconsole/key

接口参数说明

参数类型

参数名称

是否必须

具体描述

String

location

true

输入城市名或经纬度,城市名称如:北京或者131,经纬度格式为lng,lat坐标如: location=116.305145,39.982368;全国值为all,返回省会城市自治区,港澳台天气情况多城市天气预报中间"|"分隔,location=116.305145,39.982368| 122.305145,36.982368|….

String

output

false

输出的数据格式,默认为xml格式,当output设置为’json’时,输出的为json格式的数据;

String

coord_type


false

请求参数坐标类型,默认为gcj02经纬度坐标。允许的值为bd09ll、bd09mc、gcj02、wgs84。bd09ll表示百度经纬度坐标,bd09mc表示百度墨卡托坐标,gcj02表示经过国测局加密的坐标。wgs84表示gps获取的坐标。

String

ak

true

访问应用(ak) 需要在百度lbs开放平台申请

返回结果

参数名称

含义

说明

currentCity

当前城市

返回城市名

status

返回结果状态信息

 

date

当前时间

年-月-日

results

天气预报信息

白天可返回近期3天的天气情况(今天、明天、后天)、晚上可返回近期4天的天气情况(今天、明天、后天、大后天)

results.currentCity

当前城市

 

results.weather_data

天气预报时间

 

weather_data.dayPictureUrl

白天的天气预报图片url

 

weather_data.nightPictureUrl

晚上的天气预报图片url

 

weather_data.weather

天气状况

所有天气情况(”|”分隔符)

weather_data.wind

风力

 

weather_data.temperature

温度

 

返回JSON格式的数据

{
    "error": 0,
    "status": "success",
    "date": "2014-09-17",
    "results": [
        {
            "currentCity": "北京",
            "pm25": "153",
            "index": [
                {
                    "title": "穿衣",
                    "zs": "较舒适",
                    "tipt": "穿衣指数",
                    "des": "建议着薄外套或牛仔衫裤等服装。年老体弱者宜着夹克衫、薄毛衣等。昼夜温差较大,注意适当增减衣服。"
                },
                {
                    "title": "洗车",
                    "zs": "较适宜",
                    "tipt": "洗车指数",
                    "des": "较适宜洗车,未来一天无雨,风力较小,擦洗一新的汽车至少能保持一天。"
                },
                {
                    "title": "旅游",
                    "zs": "适宜",
                    "tipt": "旅游指数",
                    "des": "天气较好,但丝毫不会影响您出行的心情。温度适宜又有微风相伴,适宜旅游。"
                },
                {
                    "title": "感冒",
                    "zs": "少发",
                    "tipt": "感冒指数",
                    "des": "各项气象条件适宜,无明显降温过程,发生感冒机率较低。"
                },
                {
                    "title": "运动",
                    "zs": "较适宜",
                    "tipt": "运动指数",
                    "des": "天气较好,但考虑气温较低,推荐您进行室内运动,若户外适当增减衣物并注意防晒。"
                },
                {
                    "title": "紫外线强度",
                    "zs": "弱",
                    "tipt": "紫外线强度指数",
                    "des": "紫外线强度较弱,建议出门前涂擦SPF在12-15之间、PA+的防晒护肤品。"
                }
            ],
            "weather_data": [
                {
                    "date": "周三 09月17日 (实时:21℃)",
                    "dayPictureUrl": "http://api.map.baidu.com/images/weather/day/duoyun.png",
                    "nightPictureUrl": "http://api.map.baidu.com/images/weather/night/qing.png",
                    "weather": "多云转晴",
                    "wind": "微风",
                    "temperature": "23 ~ 12℃"
                },
                {
                    "date": "周四",
                    "dayPictureUrl": "http://api.map.baidu.com/images/weather/day/qing.png",
                    "nightPictureUrl": "http://api.map.baidu.com/images/weather/night/duoyun.png",
                    "weather": "晴转多云",
                    "wind": "微风",
                    "temperature": "25 ~ 15℃"
                },
                {
                    "date": "周五",
                    "dayPictureUrl": "http://api.map.baidu.com/images/weather/day/yin.png",
                    "nightPictureUrl": "http://api.map.baidu.com/images/weather/night/yin.png",
                    "weather": "阴",
                    "wind": "微风",
                    "temperature": "23 ~ 15℃"
                },
                {
                    "date": "周六",
                    "dayPictureUrl": "http://api.map.baidu.com/images/weather/day/qing.png",
                    "nightPictureUrl": "http://api.map.baidu.com/images/weather/night/qing.png",
                    "weather": "晴",
                    "wind": "微风",
                    "temperature": "29 ~ 16℃"
                }
            ]
        }
    ]
}

返回XML格式的数据



1. <?xml version="1.0" encoding="utf-8"?>  
2.   
3. <CityWeatherResponse>   
4. <error>0</error>   
5. <status>success</status>   
6. <date>2014-09-17</date>   
7. <results>   
8. <currentCity>北京</currentCity>   
9. <weather_data>   
10. <date>周三 09月17日 (实时:21℃)</date>   
11. <dayPictureUrl>http://api.map.baidu.com/images/weather/day/duoyun.png</dayPictureUrl>   
12. <nightPictureUrl>http://api.map.baidu.com/images/weather/night/qing.png</nightPictureUrl>   
13. <weather>多云转晴</weather>   
14. <wind>微风</wind>   
15. <temperature>23 ~ 12℃</temperature>   
16. <date>周四</date>   
17. <dayPictureUrl>http://api.map.baidu.com/images/weather/day/qing.png</dayPictureUrl>   
18. <nightPictureUrl>http://api.map.baidu.com/images/weather/night/duoyun.png</nightPictureUrl>   
19. <weather>晴转多云</weather>   
20. <wind>微风</wind>   
21. <temperature>25 ~ 15℃</temperature>   
22. <date>周五</date>   
23. <dayPictureUrl>http://api.map.baidu.com/images/weather/day/yin.png</dayPictureUrl>   
24. <nightPictureUrl>http://api.map.baidu.com/images/weather/night/yin.png</nightPictureUrl>   
25. <weather>阴</weather>   
26. <wind>微风</wind>   
27. <temperature>23 ~ 15℃</temperature>   
28. <date>周六</date>   
29. <dayPictureUrl>http://api.map.baidu.com/images/weather/day/qing.png</dayPictureUrl>   
30. <nightPictureUrl>http://api.map.baidu.com/images/weather/night/qing.png</nightPictureUrl>   
31. <weather>晴</weather>   
32. <wind>微风</wind>   
33. <temperature>29 ~ 16℃</temperature>   
34. </weather_data>   
35. <index>   
36. <title>穿衣</title>   
37. <zs>较舒适</zs>   
38. <tipt>穿衣指数</tipt>   
39. <des>建议着薄外套或牛仔衫裤等服装。年老体弱者宜着夹克衫、薄毛衣等。昼夜温差较大,注意适当增减衣服。</des>   
40. <title>洗车</title>   
41. <zs>较适宜</zs>   
42. <tipt>洗车指数</tipt>   
43. <des>较适宜洗车,未来一天无雨,风力较小,擦洗一新的汽车至少能保持一天。</des>   
44. <title>旅游</title>   
45. <zs>适宜</zs>   
46. <tipt>旅游指数</tipt>   
47. <des>天气较好,但丝毫不会影响您出行的心情。温度适宜又有微风相伴,适宜旅游。</des>   
48. <title>感冒</title>   
49. <zs>少发</zs>   
50. <tipt>感冒指数</tipt>   
51. <des>各项气象条件适宜,无明显降温过程,发生感冒机率较低。</des>   
52. <title>运动</title>   
53. <zs>较适宜</zs>   
54. <tipt>运动指数</tipt>   
55. <des>天气较好,但考虑气温较低,推荐您进行室内运动,若户外适当增减衣物并注意防晒。</des>   
56. <title>紫外线强度</title>   
57. <zs>弱</zs>   
58. <tipt>紫外线强度指数</tipt>   
59. <des>紫外线强度较弱,建议出门前涂擦SPF在12-15之间、PA+的防晒护肤品。</des>   
60. </index>   
61. <pm25>153</pm25>   
62. </results>   
63. </CityWeatherResponse>