当前位置:首页 » 安卓系统 » android天气接口

android天气接口

发布时间: 2022-06-05 18:46:46

㈠ android中如何获取当前位置的天气

1、首先获取位置(坐标或城市),可以使用网络地图API、高德地图API

2、利用坐标或城市获取天气。需要使用三方天气API。例如:Mob天气接口、天气接口、聚合数据接口、国家气象局

㈡ android怎样使用天气预报接口 实现天气预报

使用搜索引擎可以得到很多的天气预报接口,这里以某个api为例

http://wthrcdn.etouch.cn/WeatherApi

参数为city=城市名称

尝试获取南昌的天气预报

http://wthrcdn.etouch.cn/WeatherApi?city=南昌


得到下面xml数据

java"><?xmlversion="1.0"encoding="utf-8"?>

<resp>
<city>南昌</city>
<updatetime>16:55</updatetime>
<wen>5</wen>
<fengli>3级</fengli>
<shi>90%</shi>
<fengxiang>北风</fengxiang>
<sunrise_1>06:54</sunrise_1>
<sunset_1>17:19</sunset_1>
<sunrise_2/>
<sunset_2/>
<environment>
<aqi>26</aqi>
<pm25>13</pm25>
<suggest>各类人群可自由活动</suggest>
<quality>优</quality>
<MajorPollutants/>
<o3>44</o3>
<co>1</co>
<pm10>14</pm10>
<so2>4</so2>
<no2>27</no2>
<time>16:00:00</time>
</environment>
<yesterday>
<date_1>4日星期五</date_1>
<high_1>高温11℃</high_1>
<low_1>低温7℃</low_1>
<day_1>
<type_1>阴</type_1>
<fx_1>无持续风向</fx_1>
<fl_1>微风</fl_1>
</day_1>
<night_1>
<type_1>小到中雨</type_1>
<fx_1>北风</fx_1>
<fl_1>3-4级</fl_1>
</night_1>
</yesterday>
<forecast>
<weather>
<date>5日星期六</date>
<high>高温7℃</high>
<low>低温5℃</low>
<day>
<type>中到大雨</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</day>
<night>
<type>小到中雨</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</night>
</weather>
<weather>
<date>6日星期天</date>
<high>高温10℃</high>
<low>低温5℃</low>
<day>
<type>阴</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</day>
<night>
<type>多云</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</night>
</weather>
<weather>
<date>7日星期一</date>
<high>高温13℃</high>
<low>低温6℃</low>
<day>
<type>多云</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</day>
<night>
<type>晴</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</night>
</weather>
<weather>
<date>8日星期二</date>
<high>高温13℃</high>
<low>低温7℃</low>
<day>
<type>晴</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</day>
<night>
<type>多云</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</night>
</weather>
<weather>
<date>9日星期三</date>
<high>高温13℃</high>
<low>低温10℃</low>
<day>
<type>小雨</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</day>
<night>
<type>小雨</type>
<fengxiang>无持续风向</fengxiang>
<fengli>微风级</fengli>
</night>
</weather>
</forecast>
<shus>
<shu>
<name>晨练指数</name>
<value>不宜</value>
<detail>有较强降水,请避免户外晨练,建议在室内做适当锻炼,保持身体健康。</detail>
</shu>
<shu>
<name>舒适度</name>
<value>较舒适</value>
<detail>白天有雨,人们会感到有些凉意,但大部分人完全可以接受。</detail>
</shu>
<shu>
<name>穿衣指数</name>
<value>较冷</value>
<detail>建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。</detail>
</shu>
<shu>
<name>感冒指数</name>
<value>极易发</value>
<detail>将有一次强降温过程,天气寒冷,且空气湿度较大,极易发生感冒,请特别注意增加衣服保暖防寒。</detail>
</shu>
<shu>
<name>晾晒指数</name>
<value>不宜</value>
<detail>有较强降水,不适宜晾晒。若需要晾晒,请在室内准备出充足的空间。</detail>
</shu>
<shu>
<name>旅游指数</name>
<value>较不宜</value>
<detail>天气稍凉,有微风,同时有有较强降水,会给出行产生很多麻烦,建议好还是多选择在室内活动!。</detail>
</shu>
<shu>
<name>紫外线强度</name>
<value>最弱</value>
<detail>属弱紫外线辐射天气,无需特别防护。若长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。</detail>
</shu>
<shu>
<name>洗车指数</name>
<value>不宜</value>
<detail>不宜洗车,未来24小时内有雨,如果在此期间洗车,雨水和路上的泥水可能会再次弄脏您的爱车。</detail>
</shu>
<shu>
<name>运动指数</name>
<value>较不宜</value>
<detail>有较强降水,建议您选择在室内进行健身休闲运动。</detail>
</shu>
<shu>
<name>约会指数</name>
<value>不适宜</value>
<detail>较强降水天气会给室外约会增添许多麻烦,尽量不要外出约会,最好在室内促膝谈心。</detail>
</shu>
<shu>
<name>雨伞指数</name>
<value>带伞</value>
<detail>有较强降水,您在外出的时候一定要带雨伞,以免被雨水淋湿。</detail>
</shu>
</shus>
</resp>


得到数据后使用XML解析数据即可,最好是建立一个实体类来存储数据

下面是使用DOM方式解析部分数据代码

DocumentBuilderbuilder=DocumentBuilderFactory.newInstance().newDocumentBuilder();
//is是网络连接得到的输入流
Documentdoc=builder.parse(is);
if(doc==null)thrownewException();

Elementelement=doc.getDocumentElement();
NodeListchildList=element.getChildNodes();
for(inti=0;i<childList.getLength();i++){
Elemente=(Element)childList.item(i);
Stringtag=e.getTagName();
Stringtext=e.getTextContent();
if("city".equals(tag)){
//城市
}elseif("updatetime".equals(tag)){
//更新时间
}elseif("wen".equals(tag)){
//即时温度
}elseif("fengli".equals(tag)){
//风力
}elseif("shi".equals(tag)){
//湿度
}elseif("fengxiang".equals(tag)){
//风向
}
}

㈢ android端免费获取天气信息的服务器接口有么

有,墨迹天气,很少流量

㈣ Android weather API 昨天好像发现 m.weather.com.cn/data

这是官方论坛上的通知,那个接口已经停用,可以申请新的接口使用,谢谢。

致广大气象开发爱好者:
近期很多网友反馈http://m.weather.com.cn/data/101010100.html该地址的数据不更新,特此声明,该地址并非官方发布的面向公众的数据接口。后续将不在维护!

如需使用天气数据,请到官方正式对外提供的平台(SmartWeatherAPI平台),按固定格式填写表格申请使用:

申请地址:http://smart.weather.com.cn/wzfw/smart/weatherapi.shtml

该接口免费向公众提供3天天气预报、实况、指数等数据信息,如需申请开通更多数据接口,请走商务合作渠道!

感谢大家配合!

㈤ android 高德2.10如何获取天气预报啊

恩,调用谷歌天气预报的api,返回xml,解析一下显示在控件里就可以了!

㈥ android开发 怎么显示天气

本经验将介绍Android如何获取天气预报主要使用了中国天气网的接口,使用webView显示。
工具/原料
Android Studio
方法/步骤
首先我们打开下载安装好的Android Studio然后新建一个项目,我这里为了方便就直接添加一个Activity了

然后我们添加界面布局代码,布局如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>

<Button
android:id="@+id/bj"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bj" />

<Button
android:id="@+id/sh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sh" />

<Button
android:id="@+id/heb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/heb" />

<Button
android:id="@+id/cc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cc" />

<Button
android:id="@+id/sy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sy" />

<Button
android:id="@+id/gz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/gz" />

</LinearLayout>
<WebView android:id="@+id/webView1"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:focusable="false"
android:layout_weight="1"
/>

</LinearLayout>

然后我们添加后台代码:
package com.basillee.asus.demo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

public class MainActivity7 extends Activity implements OnClickListener {
private WebView webView; //声明WebView组件的对象

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity7);
webView=(WebView)findViewById(R.id.webView1); //获取WebView组件
webView.getSettings().setJavaScriptEnabled(true); //设置JavaScript可用
webView.setWebChromeClient(new WebChromeClient()); //处理JavaScript对话框
webView.setWebViewClient(new WebViewClient()); //处理各种通知和请求事件,如果不使用该句代码,将使用内置浏览器访问网页
webView.loadUrl("http://m.weather.com.cn/m/pn12/weather.htm "); //设置默认显示的天气预报信息
webView.setInitialScale(57*4); //放网页内容放大4倍
Button bj=(Button)findViewById(R.id.bj); //获取布局管理器中添加的“北京”按钮
bj.setOnClickListener(this);
Button sh=(Button)findViewById(R.id.sh); //获取布局管理器中添加的“上海”按钮
sh.setOnClickListener(this);
Button heb=(Button)findViewById(R.id.heb); //获取布局管理器中添加的“哈尔滨”按钮
heb.setOnClickListener(this);
Button cc=(Button)findViewById(R.id.cc); //获取布局管理器中添加的“长春”按钮
cc.setOnClickListener(this);
Button sy=(Button)findViewById(R.id.sy); //获取布局管理器中添加的“沈阳”按钮
sy.setOnClickListener(this);
Button gz=(Button)findViewById(R.id.gz); //获取布局管理器中添加的“广州”按钮
gz.setOnClickListener(this);
}
@Override
public void onClick(View view){
switch(view.getId()){
case R.id.bj: //单击的是“北京”按钮
openUrl("101010100T");
break;
case R.id.sh: //单击的是“上海”按钮
openUrl("101020100T");
break;
case R.id.heb: //单击的是“哈尔滨”按钮
openUrl("101050101T");
break;
case R.id.cc: //单击的是“长春”按钮
openUrl("101060101T");
break;
case R.id.sy: //单击的是“沈阳”按钮
openUrl("101070101T");
break;
case R.id.gz: //单击的是“广州”按钮
openUrl("101280101T");
break;
}
}
//打开网页的方法
private void openUrl(String id){
webView.loadUrl("http://m.weather.com.cn/m/pn12/weather.htm?id="+id+" "); //获取并显示天气预报信息
}
}

然后我们点击Android Studio上面的运行按钮:

这里要访问网络我们要添加权限:
<uses-permission android:name="android.permission.INTERNET" />

6
我们然后可以在模拟器上面可以看到获取的天气情况

㈦ android怎么获取实时天气

准备工作:
1.下载华为能力SDK;http://imax.vmall.com/nj-campus/universityEpDown/toDownPage
2.申请一个应用获取appId和appkey,待会要用到。

简单的思路就是先通过网络或者gps获取到当前位置的经纬度,然后通过sdk查询温度,获取结果。
具体步骤如下:
1.创建工程
把sdk中jar包拖到工程中的libs文件夹下面。

2.主类代码如下
package com.empty.weatherreport;
import com.empty.weatherreport.WeatherUtil.SCell;
import com.empty.weatherreport.WeatherUtil.SItude;
import com.imax.vmall.sdk.android.common.adapter.ServiceCallback;
import com.imax.vmall.sdk.android.entry.CapabilityService;
import com.imax.vmall.sdk.android.entry.CommonService;
import com.imax.vmall.sdk.android.huawei.weather.WeatherService;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
public class WeatherActivity extends Activity {

private MyHandler myHandler;
private ProgressDialog mProgressDialog;
private Location mLocation;
private boolean sdkStatus;
//Tool to get weather
/**
* CommonService
*/
private CommonService cs;
/**
* WeatherService
*/
private WeatherService weather;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weather);
sdkStatus=false;
myHandler=new MyHandler();
//初始化业务接口实例
weather = CapabilityService.getWeatherServiceInstance();
//实例化CommonService
cs=CommonService.getInstance();
initSDK();
}
private void initSDK()
{
//应用ID,请去iMAX平台注册申请
String appId="******";
//应用Key
String appKey="******";
//通过CommonService调用鉴权接口,在调用其它能力前必须保证鉴权初始化成功
cs.init(WeatherActivity.this,appId, appKey, new ServiceCallback() {
public void onError(String arg0) {
// TODO Auto-generated method stub
//设置消息
Message msg = new Message();
msg = new Message();
msg.what = 2;
msg.obj = "SDK initialize failed!";
myHandler.sendMessage(msg);
}
public void onComplete(String arg0) {
// TODO Auto-generated method stub
//设置消息
Message msg = new Message();
msg = new Message();
msg.what = 2;
msg.obj = "SDK initialize success!";
sdkStatus=true;
myHandler.sendMessage(msg);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_weather, menu);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
// TODO Auto-generated method stub
if(item.getItemId()==R.id.menu_settings) Toast.makeText(getApplicationContext(), "Ha", Toast.LENGTH_SHORT).show();
if(item.getItemId()==R.id.menu_weather)
{
if(sdkStatus)
{
/** 弹出一个等待状态的框 */
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("Waiting...");
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.show();
WeatherThread m = new WeatherThread();
new Thread(m).start();
}
else
Toast.makeText(getApplicationContext(), "SDK not installed", Toast.LENGTH_SHORT).show();
}
return super.onMenuItemSelected(featureId, item);
}
/** 显示结果 */
private void showResult(String s) {
String tmp[]=s.split("\"");
for(int i=0;i<tmp.length;i++)
Log.i("tmp"+i, tmp[i]);
new AlertDialog.Builder(this) .setTitle("Weather") .setMessage("latitude:"+mLocation.getLatitude()+"\n longitude:"
+mLocation.getLongitude()+"\ntmperature:"+tmp[21]) .show();
}
class MyHandler extends Handler {
public MyHandler() {
}
public MyHandler(Looper L) {
super(L);
}
// 子类必须重写此方法,接管数据
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
Log.d("MyHandler", "handleMessage......");
/** 显示结果 */
switch(msg.what)
{
case 1:
Log.i("Error", "case1");
mProgressDialog.dismiss();
showResult((String)msg.obj);
break;
case 2:
Toast.makeText(getApplicationContext(), (String)msg.obj, Toast.LENGTH_SHORT).show();
break;
default:;
}
super.handleMessage(msg);
// 此处可以更新UI
}
}
class WeatherThread implements Runnable {
public void run() {
final Message msg = new Message();
msg.what=1;
try {
mLocation=getLocation(WeatherActivity.this);
weather.getWeather(Double.toString(mLocation.getLongitude()),Double.toString(mLocation.getLatitude()), new ServiceCallback()
{
public void onError(String arg0)
{
//api接口调用错误响应
Log.i("Error", "getWeather error:"+arg0);
//设置消息
msg.obj = arg0;
/** 关闭对话框 */
myHandler.sendMessage(msg); // 向Handler发送消息,更新UI
}
public void onComplete(String arg0)
{
//api接口调用成功响应
Log.i("Complete", "getWeather complete:"+arg0);
//设置消息
msg.obj = arg0;
/** 关闭对话框 */
myHandler.sendMessage(msg); // 向Handler发送消息,更新UI
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//Get the Location by GPS or WIFI
public Location getLocation(Context context) {
LocationManager locMan = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
Location location = locMan
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location == null) {
location = locMan
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
return location;
}
}

3.载manifest文件中添加权限
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" >
</uses-permission>
<uses-permission android:name="android.permission.INTERNET" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

㈧ 编一个android的简单天气预报程序大概要用到哪些类都是干什么的可以简单说一下么

我可能会用到这几个类:

  1. 天气数据定义,比如晴天阴天,风向,风力,湿度,温度等。

  2. 网络请求和数据解析,因为功能比较简单,所以可以考虑放在一个类里。

  3. 界面类,简单的就只有一个activity好了,对应一些简单的功能,刷新天气之类的。

热点内容
我的世界怎么扩容服务器内存 发布:2024-05-05 17:19:54 浏览:47
java读取文件字符 发布:2024-05-05 17:15:18 浏览:11
三星怎么应用加密 发布:2024-05-05 17:13:18 浏览:151
cad字体在那个文件夹 发布:2024-05-05 17:08:20 浏览:330
什么时候用编译器 发布:2024-05-05 17:08:20 浏览:765
应急救援脚本 发布:2024-05-05 17:08:17 浏览:337
我的世界搭建无正版验证服务器 发布:2024-05-05 17:03:48 浏览:818
我的世界服务器地址宝可梦 发布:2024-05-05 17:00:16 浏览:255
dede企业源码 发布:2024-05-05 16:57:53 浏览:786
如何查看java版本 发布:2024-05-05 16:45:05 浏览:494