1.想要实现的页面
2.填充页面需要的数据:
城市
当前温度,天气状况(如多云),风向,风力,今天的最低温度,最高温度,当前的空气质量(这个小时)。
最近9个小时的数据:
天气状况,温度,空气质量。
风力,风向。
降雨量。
紫外线强度(如4级)。
但我没有数据来源 ,所以看了这篇文章:
最好的 6 个免费天气 API 接口对比测评_天气api_蒋川_卡拉云的博客-CSDN博客
尝试使用高德地图api:
卡在了这里,明明输入了验证码,但还是不让下一步。
尝试使用心知天气api:
我就是想实践一下,也没钱,所以使用的是免费版
关于API密钥:
https://api.seniverse.com/v3/weather/now.json?key=your_private_key&location=beijing&language=zh-Hans&unit=c
但是有些我想用的api,我没有访问权限,,,
免费版的接口太少了,满足不了我的需求,但是非常能理解。
尝试使用和风天气API:
使用和风天气接口获取天气信息_huaweichenai的博客-CSDN博客
下面的内容参考上面的文章:
1.获取实时地址
https://devapi.qweather.com/v7/weather/now?location=101010100&key=你的KEY
KEY的位置:
{
"code":"200",
"updateTime":"2023-04-05T19:12+08:00",
"fxLink":"https://www.qweather.com/weather/beijing-101010100.html",
"now":{
"obsTime":"2023-04-05T19:06+08:00",//数据观察时间
"temp":"14",//温度
"feelsLike":"10",//体感温度
"icon":"150",//天气状况和图标的代码,图标可通过天气状况和图标下载
"text":"晴",//天气状况的文字描述,包括阴晴雨雪等天气状态的描述
"wind360":"225",
"windDir":"西南风",
"windScale":"4",
"windSpeed":"22",
"humidity":"52",
"precip":"0.0",
"pressure":"1009",
"vis":"14",
"cloud":"10",
"dew":"4"
},
"refer":{
"sources":[
"QWeather",
"NMC",
"ECMWF"
],
"license":[
"CC BY-SA 4.0"
]
}
}
2. 获取未来3天天气(包括今天)
https://devapi.qweather.com/v7/weather/3d?location=101010100&key=你的KEY
{
"code":"200",
"updateTime":"2023-04-05T19:35+08:00",
"fxLink":"https://www.qweather.com/weather/beijing-101010100.html",
"daily":[
{
"fxDate":"2023-04-05",
"sunrise":"05:53",
"sunset":"18:43",
"moonrise":"17:43",
"moonset":"05:35",
"moonPhase":"盈凸月",
"moonPhaseIcon":"803",
"tempMax":"16",//当天最高温度
"tempMin":"9",//当天最低温度
"iconDay":"101",
"textDay":"多云",
"iconNight":"305",
"textNight":"小雨",
"wind360Day":"334",
"windDirDay":"西北风",
"windScaleDay":"1-2",
"windSpeedDay":"11",
"wind360Night":"315",
"windDirNight":"西北风",
"windScaleNight":"1-2",
"windSpeedNight":"3",
"humidity":"60",
"precip":"0.0",
"pressure":"1007",
"vis":"21",
"cloud":"25",
"uvIndex":"6"
},
Object{...},
Object{...}
],
"refer":{
"sources":[
"QWeather",
"NMC",
"ECMWF"
],
"license":[
"CC BY-SA 4.0"
]
}
}
从这里可以获取最高温度tempMax,最低温度tempMin
而气温,风力,风向都是实时的(这个小时的)
3.未来24小时天气:
{
"code":"200",
"updateTime":"2023-04-05T19:35+08:00",
"fxLink":"https://www.qweather.com/weather/beijing-101010100.html",
"hourly":[
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...},
Object{...}
],
"refer":{
"sources":[
"QWeather",
"NMC",
"ECMWF"
],
"license":[
"CC BY-SA 4.0"
]
}
}
hourly中的Object:
{
"fxTime":"2023-04-05T21:00+08:00",//预报时间
"temp":"11",//温度
"icon":"151",//天气状况和图标的代码,图标可通过天气状况和图标下载
"text":"多云",//天气情况的文本描述
"wind360":"324",//风向360角度
"windDir":"西北风",//风向
"windScale":"3-4",//风力等级
"windSpeed":"16",//风速,公里/小时
"humidity":"63",//相对湿度,百分比数值
"pop":"7",//逐小时预报降水概率,百分比数值,可能为空
"precip":"0.0",//当前小时累计降水量,默认单位:毫米
"pressure":"1006",//大气压强,默认单位:百帕
"cloud":"56",//云量,百分比数值
"dew":"4"//露点温度
},
在这里,风力(windScale),风向(windDir),有了。
降雨量(precip)
天气状况(icon,text),温度(temp)。
没有空气质量。
4.天气预警:
https://devapi.qweather.com/v7/warning/now?location=101010100&key=你的KEY
{
"code":"200",
"updateTime":"2023-04-05T20:28+08:00",
"fxLink":"https://www.qweather.com/severe-weather/beijing-101010100.html",
"warning":[
{
"id":"10101010020230405154234732693141",
"sender":"北京市气象局",
"pubTime":"2023-04-05T15:42+08:00",
"title":"北京市气象台2023年4月05日15时40分发布大风蓝色预警信号",
"startTime":"2023-04-05T15:40+08:00",
"endTime":"2023-04-06T15:40+08:00",
"status":"active",
"level":"蓝色",
"severity":"Minor",
"severityColor":"Blue",
"type":"1006",
"typeName":"大风",
"urgency":"",
"certainty":"",
"text":"市气象台2023年4月05日15时40分发布大风蓝色预警信号:预计,6日07时至7日20时,本市有4级左右偏北风,阵风6、7级,请注意防范。",
"related":""
}
],
"refer":{
"sources":[
"12379"
],
"license":[
"CC BY-SA 4.0"
]
}
}
5.空气质量。
参考文档:
实时空气质量 for API | 和风天气开发服务 (qweather.com)
官方提供的参考文档很便利好用(应该仔细查看)。
https://devapi.qweather.com/v7/air/now?location=101010100&key=YOUR_KEY
因为我使用的是免费版,所以我的Host是devapi.qweather.com
now.category
空气质量指数级别