為了完善天氣預報功能子產品,我開發了一套資料量較為全的天氣預報,主要為全國主要城市預報。位址為:http://www.sojson.com/tianqi/
首先首頁是個定位功能,然後根據定位查詢天氣。當定位不準,或者定位到的城市沒有在我的城市範圍内,那麼就采用本省的省會做為天氣預報城市,這裡比較粗糙。
天氣預報效果圖
天氣預報,我設定了幾個背景效果,分為:天晴,下雨,污染霧霾,下雪,等幾個背景效果。
天氣晴朗效果圖:
天氣下雨效果圖
其他的自己體驗。
天氣API接口說明
接口連結:
http://www.sojson.com/tianqi/api/1011-58414.shtml
參數說明:
1011-58414
,第一個是省ID,第二個是城市ID。
傳回說明:傳回以 JSON 格式傳回。
天氣API 傳回值如下:
{
"updateTime": 1496988312667,
"alert": "2017年06月09日06時安徽省安慶市太湖縣釋出雷電黃色預警",
"temperature": 24.4,
"rain": 0.1,
"humidity": 97,
"weatherInfo": "大雨",
"feelst": 23.4,
"icomfort": {
"text": "溫暖,較舒适",
"color": "#00a44f",
"value": "1"
},
"airpressure": 996,
"speed": 1.9,
"direct": "西南風",
"power": "微風",
"title": "6小時内我縣可能發生雷電活動,請注意防範。",
"description": "1.政府及相關部門按照職責做好防雷工作;\n2.密切關注天氣,盡量避免戶外活動。",
"aqi": {
"aqi": "26.0",
"aq": "1",
"info": "優",
"description": "空氣品質令人滿意,基本無空氣污染。",
"color": "#32f43e"
},
"day7": [
{
"date": {
"date": "今天",
"md": "06月09日",
"week": "星期五"
},
"day": {
"wicon": "9",
"wdesc": "大雨",
"temp": "28℃",
"direct": "南風",
"wind": "微風"
},
"night": {
"wicon": "8",
"wdesc": "中雨",
"temp": "23℃",
"direct": "南風",
"wind": "微風"
},
"details": {
"hour": [
"17:00",
"20:00",
"23:00",
"10日02:00",
"05:00",
"08:00",
"11:00",
"14:00"
],
"wicon": [
"8",
"8",
"8",
"7",
"7",
"8",
"7",
"7"
],
"temp": [
"24.2℃",
"23.2℃",
"23.4℃",
"25.7℃",
"27.3℃",
"24.6℃",
"28.5℃",
"29.8℃"
],
"rainfall": [
"5.5毫米",
"8.9毫米",
"3.9毫米",
"1毫米",
"0.5毫米",
"8毫米",
"2.3毫米",
"1.3毫米"
],
"wind_speed": [
"0.4米/秒",
"0.6米/秒",
"1米/秒",
"1.8米/秒",
"3.1米/秒",
"3.4米/秒",
"3.7米/秒",
"2.6米/秒"
],
"wind_direction": [
"東風",
"東南風",
"東南風",
"南風",
"西南風",
"西南風",
"西風",
"西風"
],
"pressure": [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
],
"humidity": [
"95.1%",
"95.6%",
"98%",
"97.1%",
"93.7%",
"83%",
"85.6%",
"94.7%"
],
"cloudage": [
"90.7%",
"70%",
"72.9%",
"100%",
"85.5%",
"70%",
"70%",
"70%"
],
"visibility": [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
]
}
},
{
"date": {
"date": "明 天",
"md": "06月10日",
"week": "星期六"
},
"day": {
"wicon": "7",
"wdesc": "小雨",
"temp": "30℃",
"direct": "西南風",
"wind": "微風"
},
"night": {
"wicon": "4",
"wdesc": "西北雨",
"temp": "21℃",
"direct": "西南風",
"wind": "微風"
},
"details": {
"hour": [
"08:00",
"11:00",
"14:00",
"17:00",
"20:00",
"23:00",
"11日02:00",
"05:00"
],
"wicon": [
"8",
"7",
"7",
"8",
"7",
"4",
"4",
"4"
],
"temp": [
"24.6℃",
"28.5℃",
"29.8℃",
"27.6℃",
"26.2℃",
"24.3℃",
"24.1℃",
"22.6℃"
],
"rainfall": [
"8毫米",
"2.3毫米",
"1.3毫米",
"6.1毫米",
"0.1毫米",
"0.5毫米",
"0.5毫米",
"0.3毫米"
],
"wind_speed": [
"3.4米/秒",
"3.7米/秒",
"2.6米/秒",
"2米/秒",
"1.4米/秒",
"0.8米/秒",
"1.2米/秒",
"2.2米/秒"
],
"wind_direction": [
"西南風",
"西風",
"西風",
"西南風",
"西南風",
"南風",
"南風",
"南風"
],
"pressure": [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
],
"humidity": [
"83%",
"85.6%",
"94.7%",
"94.9%",
"95%",
"98.7%",
"98.7%",
"96%"
],
"cloudage": [
"70%",
"70%",
"70%",
"70%",
"42%",
"56.9%",
"99.9%",
"100%"
],
"visibility": [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
]
}
},
{
"date": {
"date": "後 天",
"md": "06月11日",
"week": "星期日"
},
"day": {
"wicon": "4",
"wdesc": "西北雨",
"temp": "25℃",
"direct": "東北風",
"wind": "4~5級"
},
"night": {
"wicon": "4",
"wdesc": "西北雨",
"temp": "20℃",
"direct": "東風",
"wind": "4~5級"
},
"details": {
"hour": [
"08:00",
"11:00",
"14:00",
"17:00",
"20:00",
"23:00",
"12日02:00",
"05:00"
],
"wicon": [
"4",
"4",
"4",
"4",
"1",
"1",
"1",
"4"
],
"temp": [
"21.2℃",
"24.8℃",
"22.5℃",
"22.4℃",
"22.3℃",
"21.8℃",
"21.4℃",
"20.8℃"
],
"rainfall": [
"0.2毫米",
"1.2毫米",
"1.9毫米",
"0.1毫米",
"無降水",
"無降水",
"無降水",
"0.1毫米"
],
"wind_speed": [
"3.4米/秒",
"2米/秒",
"1.4米/秒",
"1.1米/秒",
"1.5米/秒",
"1.5米/秒",
"1.6米/秒",
"1.5米/秒"
],
"wind_direction": [
"西南風",
"西風",
"東北風",
"東北風",
"東風",
"東北風",
"東北風",
"東北風"
],
"pressure": [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
],
"humidity": [
"85.5%",
"93.5%",
"95.6%",
"99.8%",
"98.3%",
"99%",
"98.9%",
"98.5%"
],
"cloudage": [
"99.4%",
"100%",
"100%",
"47.4%",
"45.6%",
"45.9%",
"55.3%",
"100%"
],
"visibility": [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
]
}
},
{
"date": {
"md": "06月12日",
"week": "星期一"
},
"day": {
"wicon": "2",
"wdesc": "陰",
"temp": "25℃",
"direct": "東風",
"wind": "微風"
},
"night": {
"wicon": "1",
"wdesc": "多雲",
"temp": "19℃",
"direct": "東北風",
"wind": "微風"
},
"details": {
"hour": [
"08:00",
"11:00",
"14:00",
"17:00",
"20:00",
"23:00",
"13日02:00",
"05:00"
],
"wicon": [
"4",
"2",
"2",
"2",
"2",
"1",
"1",
"1"
],
"temp": [
"20.2℃",
"21.4℃",
"24.8℃",
"22.7℃",
"23.4℃",
"22.8℃",
"22.2℃",
"19.4℃"
],
"rainfall": [
"0.1毫米",
"無降水",
"無降水",
"無降水",
"無降水",
"無降水",
"無降水",
"無降水"
],
"wind_speed": [
"1.6米/秒",
"1.8米/秒",
"2.5米/秒",
"3米/秒",
"2.3米/秒",
"2米/秒",
"2米/秒",
"1.8米/秒"
],
"wind_direction": [
"東北風",
"東北風",
"東北風",
"東北風",
"東風",
"東北風",
"東北風",
"東北風"
],
"pressure": [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
],
"humidity": [
"93.1%",
"80.2%",
"82.9%",
"89.2%",
"85%",
"88.6%",
"90.2%",
"93.8%"
],
"cloudage": [
"91.1%",
"83.7%",
"95.4%",
"94.5%",
"94%",
"79.9%",
"79.9%",
"79.9%"
],
"visibility": [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
]
}
},
{
"date": {
"md": "06月13日",
"week": "星期二"
},
"day": {
"wicon": "1",
"wdesc": "多雲",
"temp": "26℃",
"direct": "東北風",
"wind": "4~5級"
},
"night": {
"wicon": "1",
"wdesc": "多雲",
"temp": "19℃",
"direct": "東北風",
"wind": "4~5級"
},
"details": {
"hour": [
"08:00",
"11:00",
"14:00",
"17:00",
"20:00",
"23:00",
"14日02:00",
"05:00"
],
"wicon": [
"1",
"1",
"1",
"1",
"1",
"1",
"1",
"1"
],
"temp": [
"19.2℃",
"21.2℃",
"20.1℃",
"19.2℃",
"21.2℃",
"25.8℃",
"22.4℃",
"20.9℃"
],
"rainfall": [
"無降水",
"無降水",
"無降水",
"無降水",
"無降水",
"無降水",
"無降水",
"無降水"
],
"wind_speed": [
"2.1米/秒",
"2.1米/秒",
"2.3米/秒",
"2.1米/秒",
"1.8米/秒",
"3.3米/秒",
"1.8米/秒",
"2米/秒"
],
"wind_direction": [
"東北風",
"東北風",
"東北風",
"東北風",
"東風",
"東北風",
"東北風",
"東北風"
],
"pressure": [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
],
"humidity": [
"91.4%",
"91.9%",
"92.1%",
"88.9%",
"85.8%",
"86.5%",
"89.4%",
"85.2%"
],
"cloudage": [
"79.9%",
"79.9%",
"79.9%",
"79.9%",
"79.9%",
"72.5%",
"79.9%",
"79.9%"
],
"visibility": [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
]
}
},
{
"date": {
"md": "06月14日",
"week": "星期三"
},
"day": {
"wicon": "1",
"wdesc": "多雲",
"temp": "25℃",
"direct": "東北風",
"wind": "3~4級"
},
"night": {
"wicon": "1",
"wdesc": "多雲",
"temp": "20℃",
"direct": "東北風",
"wind": "3~4級"
},
"details": {
"hour": [
"08:00",
"11:00",
"14:00",
"17:00",
"20:00",
"23:00",
"15日02:00",
"05:00"
],
"wicon": [
"1",
"1",
"1",
"1",
"1",
"1",
"1",
"1"
],
"temp": [
"20.6℃",
"24.8℃",
"23.2℃",
"22.9℃",
"22.6℃",
"21.9℃",
"21.8℃",
"21.6℃"
],
"rainfall": [
"無降水",
"無降水",
"無降水",
"無降水",
"無降水",
"無降水",
"無降水",
"無降水"
],
"wind_speed": [
"2米/秒",
"2.5米/秒",
"2.3米/秒",
"1.1米/秒",
"1.8米/秒",
"2米/秒",
"1.8米/秒",
"1.2米/秒"
],
"wind_direction": [
"東北風",
"東風",
"東風",
"東北風",
"東北風",
"東北風",
"東北風",
"東北風"
],
"pressure": [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
],
"humidity": [
"77.2%",
"79.6%",
"81.1%",
"84%",
"83.2%",
"91.6%",
"90%",
"88.4%"
],
"cloudage": [
"79.9%",
"65.9%",
"79.9%",
"79.9%",
"79.9%",
"79.9%",
"79.9%",
"79.9%"
],
"visibility": [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
]
}
},
{
"date": {
"md": "06月15日",
"week": "星期四"
},
"day": {
"wicon": "1",
"wdesc": "多雲",
"temp": "25℃",
"direct": "東風",
"wind": "微風"
},
"night": {
"wicon": "10",
"wdesc": "暴雨",
"temp": "17℃",
"direct": "無持續風向",
"wind": "微風"
},
"details": {
"hour": [
"08:00",
"11:00",
"14:00",
"17:00",
"20:00",
"23:00",
"16日02:00",
"05:00"
],
"wicon": [
"1",
"1",
"1",
"1",
"1",
"2",
"2",
"2"
],
"temp": [
"20.2℃",
"24.8℃",
"22.6℃",
"20.6℃",
"20.6℃",
"20.6℃",
"20.2℃",
"19.5℃"
],
"rainfall": [
"無降水",
"無降水",
"無降水",
"無降水",
"無降水",
"無降水",
"無降水",
"無降水"
],
"wind_speed": [
"1.6米/秒",
"1.5米/秒",
"1.6米/秒",
"0.1米/秒",
"1.6米/秒",
"1.2米/秒",
"1.5米/秒",
"1.9米/秒"
],
"wind_direction": [
"東風",
"東風",
"東北風",
"東北風",
"東北風",
"北風",
"北風",
"東北風"
],
"pressure": [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
],
"humidity": [
"77%",
"79%",
"80.3%",
"81.7%",
"85.5%",
"89.4%",
"90%",
"84.7%"
],
"cloudage": [
"79.9%",
"79.9%",
"79.9%",
"79.9%",
"79.9%",
"100%",
"100%",
"91.4%"
],
"visibility": [
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
]
}
}
]
}
傳回值較大,主要就是對應的七天天氣,以及 七天的精準天氣說明。下面為您把接口參數一一說明意思。
天氣接口API 參數說明
{
"updateTime": 1496988312667,//更新時間,一般1小時以内
"alert": "2017年06月09日06時安徽省安慶市太湖縣釋出雷電黃色預警",//是否有天氣預警
"temperature": 24.4,//氣溫
"rain": 0.1,//降水
"humidity": 97,//相對濕度
"weatherInfo": "大雨",//天氣說明
"feelst": 23.4,//體感溫度
"icomfort": {//舒适度
"text": "溫暖,較舒适",
"color": "#00a44f",
"value": "1"//舒适度級别
},
"airpressure": 996,//氣壓
"speed": 1.9,//風速多少米/秒
"direct": "西南風",//風向
"power": "微風",//風力
"title": "6小時内我縣可能發生雷電活動,請注意防範。",//預警标題
"description": "1.政府及相關部門按照職責做好防雷工作;\n2.密切關注天氣,盡量避免戶外活動。",//預警内容
"aqi": {//空氣品質
"aqi": "26.0",//空氣指數
"aq": "1",//空氣級别
"info": "優",//空氣指數對應級别描述
"description": "空氣品質令人滿意,基本無空氣污染。",//空氣污染對人身傷害描述
"color": "#32f43e"//對應的顔色表示
},
//七天的天氣,這裡列了一個,這是一個數組,一共有7個Element
"day7": [
{
"date": {
"date": "今天",//哪一天
"md": "06月09日",//哪一天日期
"week": "星期五"//星期
},
"day": {//白天
"wicon": "9",//天氣标示
"wdesc": "大雨",//天氣
"temp": "28℃",//溫度
"direct": "南風",//風向
"wind": "微風"//風大小
},
"night": {
"wicon": "8",//天氣标示
"wdesc": "中雨",//天氣
"temp": "23℃",//溫度
"direct": "南風",//風向
"wind": "微風"//風大小
},
"details": {
"hour": [//對應當天8個時間段
"17:00",
"20:00",
"23:00",
"10日02:00",
"05:00",
"08:00",
"11:00",
"14:00"
],
"wicon": [//對應當天8個時間段天氣标示
"8",
"8",
"8",
"7",
"7",
"8",
"7",
"7"
],
"temp": [//對應當天8個時間段溫度
"24.2℃",
"23.2℃",
"23.4℃",
"25.7℃",
"27.3℃",
"24.6℃",
"28.5℃",
"29.8℃"
],
"rainfall": [//對應當天8個時間段降水
"5.5毫米",
"8.9毫米",
"3.9毫米",
"1毫米",
"0.5毫米",
"8毫米",
"2.3毫米",
"1.3毫米"
],
"wind_speed": [//對應當天8個時間段風速
"0.4米/秒",
"0.6米/秒",
"1米/秒",
"1.8米/秒",
"3.1米/秒",
"3.4米/秒",
"3.7米/秒",
"2.6米/秒"
],
"wind_direction": [//對應當天8個時間段風向
"東風",
"東南風",
"東南風",
"南風",
"西南風",
"西南風",
"西風",
"西風"
],
"pressure": [//對應當天8個時間段氣壓
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
],
"humidity": [//對應當天8個時間段濕度
"95.1%",
"95.6%",
"98%",
"97.1%",
"93.7%",
"83%",
"85.6%",
"94.7%"
],
"cloudage": [//對應當天8個時間段雲量
"90.7%",
"70%",
"72.9%",
"100%",
"85.5%",
"70%",
"70%",
"70%"
],
"visibility": [//對應當天8個時間段可見度
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-"
]
}
}
//這裡還有6個,省略了,一樣
]
}
個人使用,請勿商用。
轉載注明出處:本文來自sojson線上工具,JSON線上解析的:http://www.sojson.com/blog/237.html