百度天氣預報接口使用詳細


百度提供天氣預報查詢接口API,可以根據經緯度/城市名查詢天氣情況,我們可以在微信公眾平台開發中調用這一接口。

接口說明

根據經緯度/城市名查詢天氣的結果

接口示例

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

接口參數說明

參數類型 參數名稱 是否必須 具體描述
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獲取的坐標。

返回結果

參數名稱 含義 說明
currentCity 當前城市 返回城市名
status 返回結果狀態信息  
date 當前時間 年-月-日
results 天氣預報信息 白天可返回近期3天的天氣情況(今天、明天、后天)、晚上可返回近期4天的天氣情況(今天、明天、后天、大后天)
results.currentCity 當前城市  
results.weather_data weather_data.date 天氣預報時間  
weather_data.dayPictureUrl 白天的天氣預報圖片url  
weather_data.nightPictureUrl 晚上的天氣預報圖片url  
weather_data.weather 天氣狀況 所有天氣情況(”|”分隔符):晴|多雲|陰|陣雨|雷陣雨|雷陣雨伴有冰雹|雨夾雪|小雨|中雨|大雨|暴雨|大暴雨|特大暴雨|陣雪|小雪| 中雪|大雪|暴雪|霧|凍雨|沙塵暴|小雨轉中雨|中雨轉大雨|大雨轉暴雨|暴雨轉大暴雨|大暴雨轉特大暴雨|小雪轉中雪|中雪轉大雪|大雪轉暴雪|浮 塵|揚沙|強沙塵暴|霾
weather_data.wind 風力  
weather_data.temperature 溫度  

返回xml格式的數據

<CityWeatherResponse>
    <status>success</status>
    <date>2013-07-18</date>
    <results>
        <currentCity>北京市</currentCity>
        <weather_data>
            <date>周三</date>
            <dayPictureUrl>
                http://api.map.baidu.com/images/weather/day/duoyun.png
            </dayPictureUrl>
            <nightPictureUrl>
                http://api.map.baidu.com/images/weather/night/duoyun.png
            </nightPictureUrl>
            <weather>多雲</weather>
            <wind>微風</wind>
            <temperature>23℃</temperature>
            <date>周四</date>
            <dayPictureUrl>
                http://api.map.baidu.com/images/weather/day/leizhenyu.png
            </dayPictureUrl>
            <nightPictureUrl>
                http://api.map.baidu.com/images/weather/night/zhongyu.png
            </nightPictureUrl>
            <weather>雷陣雨轉中雨</weather>
            <wind>微風</wind>
            <temperature>2922℃</temperature>
            <date>周五</date>
            <dayPictureUrl>
                http://api.map.baidu.com/images/weather/day/yin.png
            </dayPictureUrl>
            <nightPictureUrl>
                http://api.map.baidu.com/images/weather/night/duoyun.png
            </nightPictureUrl>
            <weather>陰轉多雲</weather>
            <wind>微風</wind>
            <temperature>3123℃</temperature>
            <date>周六</date>
            <dayPictureUrl>
                http://api.map.baidu.com/images/weather/day/duoyun.png
            </dayPictureUrl>
            <nightPictureUrl>
                http://api.map.baidu.com/images/weather/night/duoyun.png
            </nightPictureUrl>
            <weather>多雲</weather>
            <wind>微風</wind>
            <temperature>3124℃</temperature>
        </weather_data>
        <currentCity>合肥市</currentCity>
        <weather_data>
            <date>周三</date>
            <dayPictureUrl>
                http://api.map.baidu.com/images/weather/day/duoyun.png
            </dayPictureUrl>
            <nightPictureUrl>
                http://api.map.baidu.com/images/weather/night/duoyun.png
            </nightPictureUrl>
            <weather>多雲</weather>
            <wind>東風3-4級</wind>
            <temperature>27℃</temperature>
            <date>周四</date>
            <dayPictureUrl>
                http://api.map.baidu.com/images/weather/day/duoyun.png
            </dayPictureUrl>
            <nightPictureUrl>
                http://api.map.baidu.com/images/weather/night/duoyun.png
            </nightPictureUrl>
            <weather>多雲</weather>
            <wind>東北風3-4級</wind>
            <temperature>3527℃</temperature>
            <date>周五</date>
            <dayPictureUrl>
                http://api.map.baidu.com/images/weather/day/duoyun.png
            </dayPictureUrl>
            <nightPictureUrl>
                http://api.map.baidu.com/images/weather/night/duoyun.png
            </nightPictureUrl>
            <weather>多雲</weather>
            <wind>南風</wind>
            <temperature>3527℃</temperature>
            <date>周六</date>
            <dayPictureUrl>
                http://api.map.baidu.com/images/weather/day/duoyun.png
            </dayPictureUrl>
            <nightPictureUrl>
                http://api.map.baidu.com/images/weather/night/duoyun.png
            </nightPictureUrl>
            <weather>多雲</weather>
            <wind>東風</wind>
            <temperature>3427℃</temperature>
        </weather_data>
    </results>
</CityWeatherResponse>
<weather>陣雨</weather>
<wind>東北風3-4級</wind>
<temperature>18℃</temperature>
</result>
</results>
</CityWeatherResponse>

返回json格式的數據

{
    error: 0,
    status: "success",
    date: "2013-07-17",
    results: [
        {
            currentCity: "北京市",
            weather_data: [
                {
                    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℃"
                },
                {
                    date: "明天(周四)",
                    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/leizhenyu.png",
                    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/zhongyu.png",
                    weather: "雷陣雨轉中雨",
                    wind: "微風",
                    temperature: "29~22℃"
                },
                {
                    date: "后天(周五)",
                    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/yin.png",
                    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
                    weather: "陰轉多雲",
                    wind: "微風",
                    temperature: "31~23℃"
                },
                {
                    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: "31~24℃"
                }
            ]
        },
        {
            currentCity: "合肥市",
            weather_data: [
                {
                    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: "東風3-4級",
                    temperature: "27℃"
                },
                {
                    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: "東北風3-4級",
                    temperature: "35~27℃"
                },
                {
                    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: "35~27℃"
                },
                {
                    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: "34~27℃"
                }
            ]
        }
    ]
}

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM