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智能天气闹钟应用开发经过
开发这个应用的初衷是这样产生滴,和我一块租房的同学每天早上都是骑单车上班,所以手机闹钟就会定一个刚好适合骑车的起床时间点.但是呢,有一天早上起床以后发现外面下挺大雨,肯定是不能骑车去上班了,于是就只好 ...
随机推荐
- ssh-copy-id:/usr/bin/ssh-copy-id: ERROR: No identities found
$ ssh-copy-id remote-machine 公钥,私钥已经生成,执行上述命令完毕出现如下错误: /usr/bin/ssh-copy-id: ERROR: No identities fo ...
- ARM-Linux移植之(四)——根文件系统构建
相关工具版本: busybox-1.7.0 arm-linux-4.3.2 linux-2.6.22 1.配置busybox并安装. 在我们的根文件系统中的/bin和/sbin目录下有各种命令的应 ...
- VMware虚拟机上网络连接模式bridged(桥接模式)
VMware虚拟机上网络连接模式bridged(桥接模式)的实质就是虚拟机本身利用主机的网卡对外直接作为一个真实的物理主机存在. 也就是理论上此时的虚拟机和主机没什么关系,只是和主机公用了一块网卡,其 ...
- Deep Learning 学习笔记(7):神经网络的求解 与 反向传播算法(Back Propagation)
反向传播算法(Back Propagation): 引言: 在逻辑回归中,我们使用梯度下降法求参数方程的最优解. 这种方法在神经网络中并不能直接使用, 因为神经网络有多层参数(最少两层),(?为何不能 ...
- PHP判断当前协议是否为HTTPS
function is_https() { if ( !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'o ...
- cs231n神经网络 常用激活函数
CS231n课程笔记翻译:神经网络笔记1(上) 一.常用激活函数 每个激活函数(或非线性函数)的输入都是一个数字,然后对其进行某种固定的数学操作.下面是在实践中可能遇到的几种激活函数: ——————— ...
- c# tcp udp 的使用场景
之前用tcp实现了一个案例(远程协助),后来我考虑用udp去实现它,于是又研究了下udp,我发现理论上udp可以做到,但是有一些问题不知道会不会有瓶颈 我参照网上写了一个简单的示例如下 服务端接收.发 ...
- 页面布局 frameset元素
frameset.html: <!DOCTYPE html><html lang="en"><head> <meta charset=&q ...
- linux的基本指令--第三节
查找与检索: 一.文件名查找:find . -name "test*" find 路径 查找类型 名字 未输入路径则默认当前路径 二 . 内容检索:grep &q ...
- Android 模拟MotionEvent事件 触发输入法
Android 模拟MotionEvent事件 触发输入法 android输入法layoutbutton文本编辑encoding 关键词:MotionEvent,模拟按键,模拟点击事件,主动弹出输 ...