android 百度天气接口
百度天气接口
之前有篇随笔是说中国气象的天气接口的,但那个接口不是很稳定,用一段时间过后就会获取不到数据了。
随笔地址:http://www.cnblogs.com/liangstudyhome/p/3700420.html
1.最近看到百度有个天气接口,拿来用了用,感觉挺好的,这里就说说这个接口了
百度提供天气预报查询接口API,可以根据经纬度/城市名查询天气情况。
接口说明
根据经纬度/城市名查询天气的结果
接口示例
http://api.map.baidu.com/telematics/v3/weather?location=北京&output=json&ak=yourkey
百度ak申请地址:http://lbsyun.baidu.com/apiconsole/key
AK申请到以后,就可以直接用这个接口了。
接口参数说明
| 参数类型 | 参数名称 | 是否必须 | 具体描述 |
|---|---|---|---|
| String | ak | true | 开发者密钥 |
| String | sn | false | 若用户所用ak的校验方式为sn校验时该参数必须。 |
| String | location | true | 输入城市名或经纬度,城市名称如:北京,经纬度格式为lng,lat坐标如: location=116.305145,39.982368;城市天气预报中间"|"分 隔,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 | 温度 | ||
2.在网页上查看数据接口的数据
XML格式的数据:
<?xml version="1.0" encoding="utf-8" ?>
<CityWeatherResponse>
<status>success</status>
<date>2014-05-03</date>
<results> <currentCity>北京</currentCity>
<weather_data>
<date>周六(今天, 实时:22℃)</date>
<dayPictureUrl>http://api.map.baidu.com/images/weather/day/leizhenyu.png</dayPictureUrl>
<nightPictureUrl>http://api.map.baidu.com/images/weather/night/duoyun.png</nightPictureUrl>
<weather>雷阵雨转多云</weather>
<wind>北风5-6级</wind>
<temperature>24 ~ 11℃</temperature>
<date>周日</date>
<dayPictureUrl>http://api.map.baidu.com/images/weather/day/duoyun.png</dayPictureUrl>
<nightPictureUrl>http://api.map.baidu.com/images/weather/night/qing.png</nightPictureUrl>
<weather>多云转晴</weather>
<wind>北风4-5级</wind>
<temperature>19 ~ 8℃</temperature>
<date>周一</date>
<dayPictureUrl>http://api.map.baidu.com/images/weather/day/qing.png</dayPictureUrl>
<nightPictureUrl>http://api.map.baidu.com/images/weather/night/qing.png</nightPictureUrl>
<weather>晴</weather>
<wind>微风</wind>
<temperature>21 ~ 9℃</temperature>
<date>周二</date>
<dayPictureUrl>http://api.map.baidu.com/images/weather/day/duoyun.png</dayPictureUrl>
<nightPictureUrl>http://api.map.baidu.com/images/weather/night/qing.png</nightPictureUrl>
<weather>多云转晴</weather>
<wind>微风</wind>
<temperature>21 ~ 10℃</temperature>
</weather_data>
</results>
</CityWeatherResponse>
JSON形式的数据:
{
"error": 0,
"status": "success",
"date": "2014-05-03",
"results": [
{
"currentCity": "北京",
"weather_data": [
{
"date": "周六(今天, 实时:22℃)",
"dayPictureUrl": "http://api.map.baidu.com/images/weather/day/leizhenyu.png",
"nightPictureUrl": "http://api.map.baidu.com/images/weather/night/duoyun.png",
"weather": "雷阵雨转多云",
"wind": "北风5-6级",
"temperature": "24 ~ 11℃"
},
{
"date": "周日",
"dayPictureUrl": "http://api.map.baidu.com/images/weather/day/duoyun.png",
"nightPictureUrl": "http://api.map.baidu.com/images/weather/night/qing.png",
"weather": "多云转晴",
"wind": "北风4-5级",
"temperature": "19 ~ 8℃"
},
{
"date": "周一",
"dayPictureUrl": "http://api.map.baidu.com/images/weather/day/qing.png",
"nightPictureUrl": "http://api.map.baidu.com/images/weather/night/qing.png",
"weather": "晴",
"wind": "微风",
"temperature": "21 ~ 9℃"
},
{
"date": "周二",
"dayPictureUrl": "http://api.map.baidu.com/images/weather/day/duoyun.png",
"nightPictureUrl": "http://api.map.baidu.com/images/weather/night/qing.png",
"weather": "多云转晴",
"wind": "微风",
"temperature": "21 ~ 10℃"
}
]
}
]
}
下面用一个demo来获取天气的数据(以获取json为例 就不解析了):
public class MainActivity extends Activity {
private TextView showTextView;
private AsyncHttpClient mAsyncHttpClient;
private String Url = "你的百度天气接口";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showTextView = (TextView) findViewById(R.id.showTextView);
mAsyncHttpClient = new AsyncHttpClient();
mAsyncHttpClient.get(Url, null, new JsonHttpResponseHandler() {
@Override
public void onSuccess(JSONObject result) {
super.onSuccess(result);
showTextView.setText(result.toString());
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
super.onFinish();
}
});
}
}
android 百度天气接口的更多相关文章
- PHP调用百度天气接口API
//百度天气接口API $location = "北京"; //地区 $ak = "5slgyqGDENN7Sy7pw29IUvrZ"; //秘钥,需要申请,百 ...
- 百度天气接口api
百度天气接口 以GET形式提交,返回JSON或XML URL:http://api.map.baidu.com/telematics/v3/weather?location={城市名}&out ...
- 结合vue展示百度天气接口天气预报
HTML: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- Android天气预报+百度天气接口
首先 在准备编敲代码之前有几点准备工作 1首先须要调节Android的DNS地址. (这个我会在末尾提及) http://www.eoeandroid.com/forum.php? mod=viewt ...
- Android解析中国天气接口JSon数据,应用于天气查询!
android解析Json数据是比较常见的一种操作.也是客户端和服务器进行数据交互的桥梁.下面就来看一看在android中解析JSon数据的方法吧. 首先要想获得Json数据,就必须访问相关的网络接口 ...
- C# 解析百度天气数据,Rss解析百度新闻以及根据IP获取所在城市
百度天气 接口地址:http://api.map.baidu.com/telematics/v3/weather?location=上海&output=json&ak=hXWAgbsC ...
- Android 百度地图开发(一)--- 申请API Key和在项目中显示百度地图
标签: Android百度地图API Key 分类: Android 百度地图开发(2) 最近自己想研究下地图,本来想研究google Map,但是申请API key比较坑爹,于是从百度地 ...
- Android百度地图
帖子 热搜: 二维码 聊天 二维码扫描 传感器 游戏 定位 手势绘图 小项目 相框 绘图 涂鸦 拨打电话 记事本 定时器 通话记录 短信群发 listview 音乐播放器 项目例子 百度地 ...
- android智能天气闹钟应用开发经过
开发这个应用的初衷是这样产生滴,和我一块租房的同学每天早上都是骑单车上班,所以手机闹钟就会定一个刚好适合骑车的起床时间点.但是呢,有一天早上起床以后发现外面下挺大雨,肯定是不能骑车去上班了,于是就只好 ...
随机推荐
- lnmp centos7 memcache服务器端 和 memcache memcached扩展的安装
在项目开发的时候有用到memcache,自己在本地需要搭建一个memcache环境,用于开发和测试; wget http://www.memcached.org/files/memcached-1.5 ...
- 对DDS的深度认识
我知道,我对与电子有关的所有事情都很着迷,但不论从哪个角度看,今天的现场可编程门阵列(FPGA),都显得“鹤立鸡群”,真是非常棒的器件.如果在这个智能时代,在这个领域,想拥有一技之长的你还没有关注FP ...
- 【转】wireshark抓包工具详细说明及操作使用
wireshark是非常流行的网络封包分析软件,功能十分强大.可以截取各种网络封包,显示网络封包的详细信息.使用wireshark的人必须了解网络协议,否则就看不懂wireshark了. 为了安全 ...
- 阿里云openapi接口使用,PHP,视频直播
1.下载sdk放入项目文件夹中 核心就是aliyun-php-sdk-core,它的配置文件会自动加载相应的类 2.引入文件 include_once LIB_PATH . 'ORG/aliyun-o ...
- thinkphp遇到的小问题,js文件中U方法不被解析
我想在js文件中写ajax, 写完发现异常, 本以为是js文件中不支持ajax 后来发现时地址解析错误. 也就是U方法在js文件中不被解析. 貌似thinkphp解析,tpl文件中的一些元素. js文 ...
- USB接线图
一.简介 通用串行总线(英文:Universal Serial Bus,简称USB)是连接外部装置的一个串口汇流排标准,在计算机上使用广泛,但也可以用在机顶盒和游戏机上,补充标准On-The-Go( ...
- List和Map常用的几种遍历方式
遍历一个List有以下几种方法: /*//1.普通for循环的方式: List<String> list=new ArrayList<String>(); list.add(& ...
- SDRAM 之时序收敛(学习了特权老师)
到现在我还是不太理解SDRAM的时序设置,但是可能蒙对了.(呵呵) 开发环境: quartus II 13.0 板子: DE2 EP2C35F672C6N 时序约束step 1:create cl ...
- PHP AST学习
前一阵和前同事交流在检测webshell方面的相关方法,其中提出了使用lex yacc做一套语法解析来解析字节码段来判断是否存在webshell. 后来在查找相关资料中,找到了github开源的一个工 ...
- zabbix监控MySQL部署实战
1.部署zabbix监控. 1.1 建用户组和用户 groupadd zabbix useradd -d /home/zabbix -g zabbix -m zabbix passwd zabbix ...