天气预报接口api,免费天气预报API接口
我用的是和风天气的接口,这个免费的用户只能获取三天的天气
https://free-api.heweather.com/v5/weather?city=城市&key=你的key值
城市可以是拼音或汉字,key在他的网站注册的时候会生成一个key值,个人认为相对于其他的接口,key的获取比较简单
我们可以通过ajax请求,返回json数据
ajax('post', 'https://free-api.heweather.com/v5/weather?city=青岛&key=你的key值, '', function (data) {
var data = JSON.parse(data)
var status = date.HeWeather5[0].status; //如果请求成功
console.log(data)
})
得到如下的数据
但是要注意,返回的数据,对应的值或许为空,所以要做好判断(比如aqi.co:' ' 有时为空)
{ "HeWeather5": [ { "alarms": [ { "level": "蓝色", "stat": "预警中", "title": "山东省青岛市气象台发布大风蓝色预警", "txt": "青岛市气象台2016年08月29日15时24分继续发布大风蓝色预警信号:预计今天下午到明天,我市北风风力海上6到7级阵风9级,陆地4到5阵风7级,请注意防范。", "type": "大风" } ], "aqi": { "city": { "aqi": "60", "co": "0", "no2": "14", "o3": "95", "pm10": "67", "pm25": "15", "qlty": "良", //共六个级别,分别:优,良,轻度污染,中度污染,重度污染,严重污染 "so2": "10" } }, "basic": { "city": "青岛", "cnty": "中国", "id": "CN101120201", "lat": "36.088000", "lon": "120.343000", "prov": "山东" //城市所属省份(仅限国内城市) "update": { "loc": "2016-08-30 11:52", "utc": "2016-08-30 03:52" } }, "daily_forecast": [ { "astro": { "mr": "03:09", "ms": "17:06", "sr": "05:28", "ss": "18:29" }, "cond": { "code_d": "100", "code_n": "100", "txt_d": "晴", "txt_n": "晴" }, "date": "2016-08-30", "hum": "45", "pcpn": "0.0", "pop": "8", "pres": "1005", "tmp": { "max": "29", "min": "22" }, "vis": "10", "wind": { "deg": "339", "dir": "北风", "sc": "4-5", "spd": "24" } } ], "hourly_forecast": [ { "cond": { "code": "100", "txt": "晴" }, "date": "2016-08-30 12:00", "hum": "47", "pop": "0", "pres": "1006", "tmp": "29", "wind": { "deg": "335", "dir": "西北风", "sc": "4-5", "spd": "36" } } ], "now": { "cond": { "code": "100", "txt": "晴" }, "fl": "28", "hum": "41", "pcpn": "0", "pres": "1005", "tmp": "26", "vis": "10", "wind": { "deg": "330", "dir": "西北风", "sc": "6-7", "spd": "34" } }, "status": "ok", "suggestion": { "comf": { "brf": "较舒适", "txt": "白天天气晴好,您在这种天气条件下,会感觉早晚凉爽、舒适,午后偏热。" }, "cw": { "brf": "较不宜", "txt": "较不宜洗车,未来一天无雨,风力较大,如果执意擦洗汽车,要做好蒙上污垢的心理准备。" }, "drsg": { "brf": "热", "txt": "天气热,建议着短裙、短裤、短薄外套、T恤等夏季服装。" }, "flu": { "brf": "较易发", "txt": "虽然温度适宜但风力较大,仍较易发生感冒,体质较弱的朋友请注意适当防护。" }, "sport": { "brf": "较适宜", "txt": "天气较好,但风力较大,推荐您进行室内运动,若在户外运动请注意防风。" }, "trav": { "brf": "适宜", "txt": "天气较好,风稍大,但温度适宜,是个好天气哦。适宜旅游,您可以尽情地享受大自然的无限风光。" }, "uv": { "brf": "强", "txt": "紫外线辐射强,建议涂擦SPF20左右、PA++的防晒护肤品。避免在10点至14点暴露于日光下。" } } } ] }
一、中国气象局(http://www.weather.com.cn)
1.实时接口
http://mobile.weather.com.cn/data/sk/101010100.html
http://www.weather.com.cn/data/sk/101010100.html
http://www.weather.com.cn/data/cityinfo/101010100.html
其中:101010100 是城市代码。
json数据格式:

2.一周天气预报接口
http://mobile.weather.com.cn/data/forecast/101010100.html
其中:101010100 是城市代码。
json数据格式:

3.获取全国所有城市代码列表

获取方式一(XML接口):
全国省会城市一览: http://flash.weather.com.cn/wmaps/xml/china.xml
全国县级以上城市一览,比如:
上海:http://flash.weather.com.cn/wmaps/xml/shanghai.xml
四川:http://flash.weather.com.cn/wmaps/xml/sichuan.xml
成都:http://flash.weather.com.cn/wmaps/xml/chengdu.xml
重庆:http://flash.weather.com.cn/wmaps/xml/chongqing.xml
获取方式二(XML接口):
一次性获取全国+国外主要城市,8763个城市列表信息。URL:http://mobile.weather.com.cn/js/citylist.xml
二、免费天气API接口(http://www.tianqiapi.com)
1.接口没有调用次数、频率和IP限制, 永久免费。
2.JSON接口调用文档:http://doc.tianqiapi.com/603579
3.IFrame调用:http://www.tianqiapi.com/
三、和风天气(https://www.heweather.com)
1.数据主要包含:实时天气,3天内天气预报,生活指数,空气质量。
访问流量:4000次/天。
访问频率:200次/分钟。
2.URL:https://free-api.heweather.com/v5/forecast?city=yourcity&key=yourkey
city:城市名称,city可通过城市中英文名称、ID、IP和经纬度进行查询,经纬度查询格式为:经度,纬度。例:city=北京,city=beijing,city=CN101010100,city= 60.194.130.1
key:用户认证key
3.注册页面:https://console.heweather.com/register
接口文档:https://www.heweather.com/documents/
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~