新浪天气预报接口_新浪天气app
1.Android weather API 昨天好像发现 m.weather.com.cn/data
2.如何使用百度天气预报API接口
3.国内有哪些城市较完整可以免费使用的天气 API 接口
首先可以明确一点,所有的气象数据一定都是来自官方的,以非官方名义公布天气数据应该还没有人敢,只是国家天气数据也有不准的时候,所有的公司都面临一个问题,怎么样让自己的数据比竞品更准?1、国家天气数据为什么也会不准?
国家天气数据中的一部分是地面、高空、雷达观测数据,会自动汇总到国家气象信息中心通信台。
一部分是卫星数据,比如中国的风云卫星一般需要20多分钟才能完成全球扫描,所以这部分的数据通常有半小时左右的延迟。
最后是预报数据,气象学上有一些标准模型,跑模型的时间,数据打包传输分发的时间其实是比较长的(由于数据量的关系),比如气象局可能采用欧洲中心模式系统的数据,有一些延迟,但是预报的特性就是随着时间不断接近,预测越是准确,很容易理解。就我所知,国家高校的一些研究机构也有自己的模型,也不敢说哪个就一定是最准的。
(一部分信息来自中国气象网)
2、国家天气数据可能是不全面的
有些时候我们想要通过手机传感器获得的经纬度来获取天气数据,或者通过?IP?地址来获取天气数据,这些都是很常见的需求,而国家天气数据的?API?可能不支持。
或者,地方气象台有一些地方的气象数据,它们属于省级气象数据,并不需要上报到国家级,那么自然国家天气数据的?API?不支持,但是地方依旧会公布它们。
亦或者,很多人关心 PM2.5,这些数据不是来自气象局,而是来自环保局,而且环保局还没有空气质量预报,又要从其他机构接入。
Android weather API 昨天好像发现 m.weather.com.cn/data
天气通设置登录的方法如下:
1、下载并安装应用后,点击左上角+号。
2、来到下方界面后,点击添加城市按钮。
3、之后在搜索框中输入城市并添加即可。
天气通的主要功能
天气通是国内最早的手机专业天气软件,采用权威数据源授权的天气信息,拥有国内外3000多个城市与700多个景区全覆盖的天气预报和实时天气预警信息,实时定位及时推送分钟级天气预报。还可查询城市的逐小时预报及空气质量指数,分析空气质量及趋势。
天气通,一款天气信息实时查询软件,累计4亿用户下载使用,支持全球30多万个地点的天气查询,支持国内3000多个城市与700多个景区全覆盖的天气预报和实时天气预警信息,准确定位及时推送,分钟级、公里级降水预报。支持未来40天气预报查询,10日空气质量预报,实时空气质量及空气质量等级预报,特殊天气提前发送预警信息。
天气通是新浪微博旗下生活类产品,是国内最早的免费手机天气预报软件。2011年1月,天气通安卓系统上线,同年11月,天气通IOS系统上线。
以上内容参考:百度百科—天气通
如何使用百度天气预报API接口
这是官方论坛上的通知,那个接口已经停用,可以申请新的接口使用,谢谢。
致广大气象开发爱好者:
近期很多网友反馈该地址的数据不更新,特此声明,该地址并非官方发布的面向公众的数据接口。后续将不在维护!
如需使用天气数据,请到官方正式对外提供的平台(SmartWeatherAPI平台),按固定格式填写表格申请使用:
申请地址:
该接口免费向公众提供3天天气预报、实况、指数等数据信息,如需申请开通更多数据接口,请走商务合作渠道!
感谢大家配合!
国内有哪些城市较完整可以免费使用的天气 API 接口
百度API Key申请地址:创建应用 如图:?
提交后得到API Key 如图:?
接口实例:?location=南昌&output=json&ak=你的API Key&mcode=你的数字签名SHA1;com.example.administrator.jsontest(包名)
接口参数说明
参数类型
参数名称
是否必须
具体描述
String location true 输入城市名或经纬度,城市名如北京或者131,经纬度格式为lng,lat坐标,如:location=116.305145,39.982368;全国值为all,返回省会城市自治区,港澳台天气情况多城市天气预报中间用“|”分隔,如:location=116.305145,39.982368|123.342323,36238945|...
String output false 输出的数据格式,默认为xml格式,当output设置为json时,输出的为json数据格式
String coord_type false 请求参数坐标类型,默认为gcj02经纬度坐标。允许的值为bd09ll、bd09mc、gcj02、wgs84;
返回的JSON数据
{
"error":0,
"status":"success",
"date":"2016-03-05",
"results":[
{
"currentCity":"北京",
"pm25":"144",
"index":[
{
"title":"穿衣",
"zs":"较冷",
"tipt":"穿衣指数",
"des":"建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。"},
{
"title":"洗车",
"zs":"不宜",
"tipt":"洗车指数",
"des":"不宜洗车,未来24小时内有扬沙或浮尘,如果在此期间洗车,极易很快蒙上新的灰尘。"},
{
"title":"旅游",
"zs":"一般",
"tipt":"旅游指数",
"des":"风稍大,扬沙或浮尘天气对能见度和空气质量都会有些影响,出行请注意交通安全和采取适当的防尘措施。"},
{
"title":"感冒",
"zs":"易发",
"tipt":"感冒指数",
"des":"昼夜温差大,风力较强,易发生感冒,请注意适当增减衣服,加强自我防护避免感冒。"},
{
"title":"运动",
"zs":"较不宜",
"tipt":"运动指数",
"des":"有扬沙或浮尘,建议适当停止户外运动,选择在室内进行运动,以避免吸入更多沙尘,有损健康。"},
{
"title":"紫外线强度",
"zs":"最弱",
"tipt":"紫外线强度指数",
"des":"属弱紫外线辐射天气,无需特别防护。若长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。"}
? ],
?"weather_data":[
?{
?"date":"周六 03月05日 (实时:12℃)", ?"dayPictureUrl":"",
"nightPictureUrl":"",
?"weather":"浮尘转晴",
?"wind":"北风4-5级",
?"temperature":"12 ~ -1℃"},
?{
?"date":"周日",
"dayPictureUrl":"",
"nightPictureUrl":"",
?"weather":"多云",
?"wind":"微风",
?"temperature":"10 ~ -3℃"},
?{
?"date":"周一", "dayPictureUrl":"",
"nightPictureUrl":"",
?"weather":"多云转阴",
?"wind":"微风",
?"temperature":"13 ~ 2℃"},
?{
?"date":"周二", "dayPictureUrl":"",
"nightPictureUrl":"",
?"weather":"阴转多云",
?"wind":"北风3-4级",
?"temperature":"6 ~ -1℃"}
?]}]}
3. ?我们来写个demo,代码如下:
package com.example.administrator.jsontest;
public class MainActivity extends Activity {
private Button button;
private TextView textView;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 0:
String re = (String) msg.obj;
textView.setText(re);
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
textView = (TextView) findViewById(R.id.textView);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("TAG", "点击了Button");
sendRequestWithHttpClient();
}
});
}
private void sendRequestWithHttpClient() {
new Thread(new Runnable() {
@Override
public void run() {
HttpURLConnection connection = null;
try {
URL url = new URL("南昌&output=json&ak=8ixCCFzlBB617YX7tONI2P5B&mcode=1C:6B:42:33:E8:A6:DC:A2:11:6E:26:EC:84:BD:42:E3:8E:6B:57:9A;com.example.administrator.jsontest");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
InputStream in = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
Log.i("TAG", response.toString()); parseJSONObjectOrJSONArray(response.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
//解析JSON数据
private void parseJSONObjectOrJSONArray(String jsonData) {
try {
String count = "";
JSONObject jsonObject = new JSONObject(jsonData);
JSONArray jsonArray = jsonObject.getJSONArray("results");
if (jsonArray.length() > 0) {
JSONObject object = jsonArray.getJSONObject(0);
String city = object.optString("currentCity");
JSONArray array = object.getJSONArray("weather_data");
for (int i = 0; i < array.length(); i++) {
JSONObject jsonObject1 = array.getJSONObject(i);
String dateDay = jsonObject1.optString("date");
String weather = jsonObject1.optString("weather");
String wind = jsonObject1.optString("wind");
String temperature = jsonObject1.optString("temperature");
count =count +"\n"+ dateDay + " " + weather + " " + wind + " " + temperature;
Log.i("AAA",count);
}
Message message = new Message();
message.what = 0;
message.obj = count;
handler.sendMessage(message);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
4.?运行结果如下:?
因微信公共号提供城市天气预报服务,发现网山天气预报接口和环境数据接口方面资料比较乱,而且有不少内容已经失效,下面内容由过程日志整理形成,希望可用得上。
一 天气预报
国内的天气预报数据,主要是国家气象局和国外两个来源(指数据来源)。
国外方面主要是雅虎(XML格式,谷歌已经停掉了自家的天气API);
国内数据由国家气象局提供(JSON格式)。
在知乎看到过一篇专业人士评论,雅虎可以提供全球范围的且非常精细的天气数据(小时级更新),但主要是通过计算机自动生成。而国家气象局则是各地经验丰富的专家人士结合计算机综合分析得出,在准确性上更胜一筹。我就这样信了!
国家气象局接口资源及用法
气象局的天气预报主页:移动版普通版 ,仔细挖掘这两个地址可以发现很多好东西哦。
特点:接口多,来自weather.com.cn和mobile.weather.com.cn都有,次数不限制,服务稳定,功能全面,优先推荐。
1. 实时天气接口
有多个接口,好像差别不大:
实时天气1:实时天气2:实时天气3(带时间戳): 一周天气预报接口
7天预报数据 URL: 该接口来源气象局移动版网站,目测数据最为精确,详细接口格式如下:
{"c":{"c1":"101010100","c2":"beijing","c3":"北京","c4":"beijing","c5":"北京","c6":"beijing","c7":"北京","c8":"china","c9":"中国","c10":"1","c11":"010","c12":"100000","c13":"116.391","c14":"39.904","c15":"33","c16":"AZ9010","c17":"+8"},
"f":{"f1":
[
{"fa":"01","fb":"03","fc":"10","fd":"5","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:21|17:40"},
{"fa":"07","fb":"07","fc":"19","fd":"12","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:22|17:38"},
{"fa":"02","fb":"00","fc":"15","fd":"5","fe":"8","ff":"8","fg":"3","fh":"1","fi":"06:23|17:37"},
{"fa":"00","fb":"00","fc":"16","fd":"4","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:24|17:35"},
{"fa":"00","fb":"00","fc":"18","fd":"7","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:25|17:34"},
{"fa":"00","fb":"01","fc":"18","fd":"8","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:26|17:32"},
{"fa":"01","fb":"01","fc":"16","fd":"6","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:27|17:31"}],
"f0":"201310121100"}}
详细接口分析如下:
//格式说明
var format={fa:1,fb:2,fc:温度1,fd:温度2,fe:风向1,ff:风向2,fg:风力1,fh:风力2,fi:日出日落};
//定义天气类型
var weatherArr={"00":"晴","01":"多云","02":"阴","03":"阵雨","04":"雷阵雨","05":"雷阵雨伴有冰雹","06":"雨夹雪","07":"小雨","08":"中雨","09":"大雨","10":"暴雨","11":"大暴雨","12":"特大暴雨","13":"阵雪","14":"小雪","15":"中雪","16":"大雪","17":"暴雪","18":"雾","19":"冻雨","20":"沙尘暴","21":"小到中雨","22":"中到大雨","23":"大到暴雨","24":"暴雨到大暴雨","25":"大暴雨到特大暴雨","26":"小到中雪","27":"中到大雪","28":"大到暴雪","29":"浮尘","30":"扬沙","31":"强沙尘暴","53":"霾","99":""};
//定义风向数组
var fxArr={"0":"无持续风向","1":"东北风","2":"东风","3":"东南风","4":"南风","5":"西南风","6":"西风","7":"西北风","8":"北风","9":"旋转风"};
//定义风力数组
var flArr={"0":"微风","1":"3-4级","2":"4-5级","3":"5-6级","4":"6-7级","5":"7-8级","6":"8-9级","7":"9-10级","8":"10-11级","9":"11-12级"};
6天预报数据 URL: 该接口来源网络,应该是一个流传比较久的接口,大发现准确性和稳定性可能不稳定。接口分析如下:
{"weatherinfo":{
#基本信息
"city":"北京","city_en":"beijing","date_y":"2013年9月24日","date":"","week":"星期二","fchh":"11","cityid":"101010100",
#6天温度范围
"temp1":"22℃~11℃","temp2":"25℃~11℃","temp3":"26℃~13℃","temp4":"25℃~15℃","temp5":"25℃~16℃","temp6":"24℃~16℃",
#6天温度范围(华氏)
"tempF1":"71.6℉~51.8℉","tempF2":"77℉~51.8℉","tempF3":"78.8℉~55.4℉","tempF4":"77℉~59℉","tempF5":"77℉~60.8℉","tempF6":"75.2℉~60.8℉",
#6天天气
"weather1":"多云转晴","weather2":"晴","weather3":"晴","weather4":"晴转多云","weather5":"阴转阵雨","weather6":"多云",
#6天天气图示(每天2张)
"img1":"1","img2":"0","img3":"0","img4":"99","img5":"0","img6":"99","img7":"0","img8":"1","img9":"2","img10":"3","img11":"1","img12":"99",
"img_single":"1",
#6天天气图示文字(每天2)
"img_title1":"多","img_title2":"晴","img_title3":"晴","img_title4":"晴","img_title5":"晴","img_title6":"晴","img_title7":"晴","img_title8":"多云","img_title9":"阴","img_title10":"阵雨","img_title11":"多云","img_title12":"多云",
"img_title_single":"多云",
#6天风
"wind1":"北风3-4级转微风","wind2":"微风","wind3":"微风","wind4":"微风","wind5":"微风","wind6":"微风",
"fx1":"北风","fx2":"微风",
#6天风力情况
"fl1":"3-4级转小于3级","fl2":"小于3级","fl3":"小于3级","fl4":"小于3级","fl5":"小于3级","fl6":"小于3级",
#24小时内
"index":"较冷","index_d":"建议着大衣、呢外套加毛衣、卫衣等服装。体弱者宜着厚外套、厚毛衣。因昼夜温差较大,注意增减衣服。",
#48小时内
"index48":"较舒适","index48_d":"建议着薄外套或牛仔衫裤等服装。年老体弱者宜着夹克衫、薄毛衣等。昼夜温差较大,注意适当增减衣服。",
#紫外 洗车 旅游 舒适指数 晨练 晾晒 过敏
"index_uv":"弱",
"index48_uv":"强",
"index_xc":"适宜",
"index_tr":"适宜",
"index_co":"舒",
"st1":"21","st2":"12","st3":"24","st4":"12","st5":"25","st6":"14", #不明
"index_cl":"较适宜",
"index_ls":"适宜",
"index_ag":"极易发"
}}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。