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智能天气闹钟应用开发经过
开发这个应用的初衷是这样产生滴,和我一块租房的同学每天早上都是骑单车上班,所以手机闹钟就会定一个刚好适合骑车的起床时间点.但是呢,有一天早上起床以后发现外面下挺大雨,肯定是不能骑车去上班了,于是就只好 ...
随机推荐
- php小白和菜鸟 上班路上可以看的修行博客
上班地铁 公交上我们不要去追剧 不要去打游戏 不要看看有效性的海量新闻, 我们需要去技术博客里遨游, 下面就推荐点与php有关的可以学习的技术博客; 大部分程序员在自学的道路上不知道走了多少坑,这个视 ...
- Activity小技巧
随时随地退出程序 新建一个结合类对所有活动进行管理. public class ActivityCollector{ public static List<Activity> activi ...
- 【转】理解JMeter聚合报告(Aggregate Report)
Aggregate Report 是 JMeter 常用的一个 Listener,中文被翻译为“聚合报告”.今天再次有同行问到这个报告中的各项数据表示什么意思,顺便在这里公布一下,以备大家查阅. 如果 ...
- 【转】Jmeter压力测试模拟并发
jmeter下载地址:http://jmeter.apache.org/download_jmeter.cgi JMeterPlugins(jmeter插件):http://jmeter-plugin ...
- telnet WIN7设置回显办法
windows 2000及XP默认是关闭telnet回显的,这样在操作上很不方便,要让Telnet程序实现本地回显可以按如下步骤操作:1.在命令窗口中运行不带任何参数的telnet命令,执行 /hel ...
- 1127 ZigZagging on a Tree
题意:中序序列+后序序列构建二叉树,之字形输出其层序序列. 思路:在结点的数据域中额外增加一个layer表示结点所在的层次,并定义vector<int> zigzag[maxn]存放最终结 ...
- springboot成神之——swagger文档自动生成工具
本文讲解如何在spring-boot中使用swagger文档自动生成工具 目录结构 说明 依赖 SwaggerConfig 开启api界面 JSR 303注释信息 Swagger核心注释 User T ...
- babel-preset-latest使用介绍
本文介绍babel中的babel-preset-latest插件 简介 该插件的作用是包含了每年的js代码转换规则 默认包含es2015,es2016,es2017,默认对这些代码都会进行转码,从而方 ...
- DRF之解析器组件及序列化组件
知识点复习回顾一:三元运算 三元运算能够简化我们的代码, 请看如下代码: # 定义两个变量 a = 1 b = 2 # 判断a的真假值,如果为True,则将判断表达式的前面的值赋给c,否则将判断表达 ...
- Sql Server 2005如何导入DBF文件?
提问者采纳 select * into 要生成的SQL表名 from OPENROWSET('MICROSOFT.JET.OLEDB.4.0','dBase IV;HDR=NO;IMEX=2;DA ...