當前位置:首頁 » 安卓系統 » 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好了,對應一些簡單的功能,刷新天氣之類的。

熱點內容
html5android教程視頻下載 發布:2024-04-26 03:09:59 瀏覽:866
伺服器的描述是什麼 發布:2024-04-26 03:08:32 瀏覽:393
個人加密 發布:2024-04-26 03:01:23 瀏覽:519
linuxusbgadget 發布:2024-04-26 02:52:54 瀏覽:303
我的世界空島世界伺服器地址 發布:2024-04-26 01:39:08 瀏覽:248
尼爾機械紀元加密 發布:2024-04-26 01:37:11 瀏覽:867
在控制台輸出sql語句 發布:2024-04-26 01:08:12 瀏覽:432
動畫java 發布:2024-04-26 01:02:40 瀏覽:12
得力文件夾5302 發布:2024-04-26 00:21:32 瀏覽:91
您的個人文件夾 發布:2024-04-26 00:03:12 瀏覽:68