安卓天气预报源代码(基于android的天气预报app开发)
android怎样使用天气预报接口 实现天气预报
使用搜索引擎可以得到很多的天气预报接口,这里以某个api为例
参数为city=城市名称
尝试获取南昌的天气预报
南昌
得到下面xml数据
?xml version="1.0" encoding="utf-8"?
resp
city南昌/city
updatetime16:55/updatetime
wendu5/wendu
fengli3级/fengli
shidu90%/shidu
fengxiang北风/fengxiang
sunrise_106:54/sunrise_1
sunset_117:19/sunset_1
sunrise_2/
sunset_2/
environment
aqi26/aqi
pm2513/pm25
suggest各类人群可自由活动/suggest
quality优/quality
MajorPollutants/
o344/o3
co1/co
pm1014/pm10
so24/so2
no227/no2
time16:00:00/time
/environment
yesterday
date_14日星期五/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_13-4级/fl_1
/night_1
/yesterday
forecast
weather
date5日星期六/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
date6日星期天/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
date7日星期一/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
date8日星期二/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
date9日星期三/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
zhishus
zhishu
name晨练指数/name
value不宜/value
detail有较强降水,请避免户外晨练,建议在室内做适当锻炼,保持身体健康。/detail
/zhishu
zhishu
name舒适度/name
value较舒适/value
detail白天有雨,人们会感到有些凉意,但大部分人完全可以接受。/detail
/zhishu
zhishu
name穿衣指数/name
value较冷/value
detail建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。/detail
/zhishu
zhishu
name感冒指数/name
value极易发/value
detail将有一次强降温过程,天气寒冷,且空气湿度较大,极易发生感冒,请特别注意增加衣服保暖防寒。/detail
/zhishu
zhishu
name晾晒指数/name
value不宜/value
detail有较强降水,不适宜晾晒。若需要晾晒,请在室内准备出充足的空间。/detail
/zhishu
zhishu
name旅游指数/name
value较不宜/value
detail天气稍凉,有微风,同时有有较强降水,会给出行产生很多麻烦,建议好还是多选择在室内活动!。/detail
/zhishu
zhishu
name紫外线强度/name
value最弱/value
detail属弱紫外线辐射天气,无需特别防护。若长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。/detail
/zhishu
zhishu
name洗车指数/name
value不宜/value
detail不宜洗车,未来24小时内有雨,如果在此期间洗车,雨水和路上的泥水可能会再次弄脏您的爱车。/detail
/zhishu
zhishu
name运动指数/name
value较不宜/value
detail有较强降水,建议您选择在室内进行健身休闲运动。/detail
/zhishu
zhishu
name约会指数/name
value不适宜/value
detail较强降水天气会给室外约会增添许多麻烦,尽量不要外出约会,最好在室内促膝谈心。/detail
/zhishu
zhishu
name雨伞指数/name
value带伞/value
detail有较强降水,您在外出的时候一定要带雨伞,以免被雨水淋湿。/detail
/zhishu
/zhishus
/resp
得到数据后使用XML解析数据即可,最好是建立一个实体类来存储数据
下面是使用DOM方式解析部分数据代码
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
//is是网络连接得到的输入流
Document doc = builder.parse(is);
if(doc==null) throw new Exception();
Element element = doc.getDocumentElement();
NodeList childList = element.getChildNodes();
for(int i=0; ichildList.getLength(); i++){
Element e = (Element) childList.item(i);
String tag = e.getTagName();
String text = e.getTextContent();
if("city".equals(tag)){
//城市
}else if("updatetime".equals(tag)){
//更新时间
}else if("wendu".equals(tag)){
//即时温度
}else if("fengli".equals(tag)){
//风力
}else if("shidu".equals(tag)){
//湿度
}else if("fengxiang".equals(tag)){
//风向
}
}
求内网网页天气预报源代码!
代码使用方法:
1.点QQ空间里的自定义==》个人设置==》新建模块.
2.把代码复制进评论栏(去掉地址栏及图片栏的 http://字样)
3.提交.(ok了)
天气预报代码:
iframe name="I1" src="" width="250" height="240"
/iframe
****************************************************************************************
Flash代码:(FLASH地址要以.swf结尾)
/textareaembed src=’’http://你的Flash地址’’quality=high pluginspage=’’ ... sion=shockwaveflash’’ type=’’application/x-shockwave-flash’’ width=330 height=240/embed
透明FLASH:
/textareaembed src=http://你的Flash特效地址 wmode=transparent style="position: absolute" width=380 height=270
注:width=和height=后面的数字是填FLASH大小高矮度..
****************************************************************************************
背景音乐代码:
/textareaembed src=http://你的背景音乐地址 width=0 height=0 loop= true (此代码不显播放器)
/textareaembed src=http://你的背景音乐地址 width=2 height=2 loop= true (此代码显播放器)
1.如何得到音乐地址...
首先打开百度音乐搜索
输入歌名..格式(只能是MP3和WMA)→查找
找到歌曲..点试听..
注意:要能听见的..而且听起来不卡的....!!!!(重要)
试听里边有个播放器..播放器右上方有个地址..
右键点击地址...→复制快捷方式
进入音乐盒..点添加
把歌曲地址复制到这里..
添加好以后要在歌曲后边的绿色加号上打勾才能自动播放..!(重要)
****************************************************************************************
视频MTV代码:(地址要以.rm/.wmv/.asf/.avi/.mpg结尾)
(播放器的大小可以自己调整代码中的数值,只需改height =“高度”,width =“宽度”)
以.wmv或者.asf结尾:
/textareaembed src=http://你的视频文件地址 width=360 height=280 loop= true
以.rm结尾:
/textareaembed src=http://你的视频文件地址 type=audio/x-pn-realaudio-plugin console=clip1 controls=ImageWindow height=124 width=180 autostart=true loop=true
以.avi或者.mpg结尾:
/textareaembed src="音乐源地址" border="0" width="320" height="240" type="application/x-mplayer2"/embed
小技巧,想要当你的好友一登陆你的空间就能马上听到最新的音乐视听吗? 技巧在于代码结尾加上wid, 如下
/textareaembed src=http://你的音乐地址 width=360 height=280 wid
****************************************************************************************
电台代码:(地址要以.asp结尾的地址)
/textareaembed src= http://你的电台地址 type=audio/x-pn-realaudio-plugin console=clip1 controls=ImageWindow height=124 width=180 autostart=true loop=truebr
代码
相关作用
b加粗/b
使文字加粗
i斜体/i
使文字倾斜
u加下划线/u
给文字加下划线
s加删除线/s
给文字加删除线
pre预设格式
令文件按照原始的排版方式显示
*好用,省去了频繁插入br与p的烦恼
****************************************************************************************
艺术字代码:
发光文字代码
/textareatable style="FILTER: glow(color=#6699FF,direction=2)"
font color=#ffffff size=2要修改的文字/font
/table
其中color是阴影的颜色,可以配合网页色调改变,direction是设置阴影的强度,font color是原字体的颜色。
浮雕的文字
/textareatable style="FILTER: dropshadow(color=#6699FF, offx=1, offy=1, positive=1);"
font color=#ffffff要修改的文字/font
/table
其中color是阴影的颜色,可以配合网页色调改变,positive是设置阴影的强度,offx和offy是设置的阴影和文字的距离,font color是原字体的颜色。
阴影的文字
/textareatable style="FILTER: dropshadow(color=#cccccc, offx=2, offy=2, positive=2);"
font color=#6CABE7 size=2要修改的文字/font
/table
文本框字体
/textareaTEXTAREA STYLE="font:12px;font-family:Verdana;color:#666666"输入内容
注:字体(font-family)还可以选用Arial,Tahoma等等;color可自行设定
tr 表格列 border="5"边框宽度为5像素,bordercolor="Purple"边框颜色为紫色
td 表格栏 bgcolor="Green"表格背景颜色为绿色
****************************************************************************************
插入超链接 (请注意:如果该链接为恶意链接的话,腾讯会自动屏蔽,请大家不要乱用)
文字链接代码 /textarea点击a href=’’http://你要链接的地址’’ target=’’_blank’’文字说明/a
图片链接代码 /textareaa href="你要链接的地址" title="文字说明",_blank
****************************************************************************************
设为首页/加入收藏代码:
a target=_top href=javascript:window.external.AddFavorite(''';')〖加入收藏〗/a..a href=# onClick="this.style.behavior=''url(#default#homepage)'';this.setHomePage(''';');"【设为首页】/a
****************************************************************************************
在主页加入钟表的代码:
embed src=''时钟的连接地址''quality=high pluginspage=''';' type=''application/x-shockwave-flash'' width=100(宽) height=100(高)/embed
其中宽和高是 FLASH显示出来的宽度和高度
把以上代码放在新建版快的评论栏中,图片地址和连接地址清空,什么都不要留!
一直到
........................./Clock129.swf
****************************************************************************************
图片上下移动代码:
图片从下往上移动的友情连接代码。效果可以在我主页看到
新建立一个模块,然后将下面的代码加入评论中!
你只需要修改代码中,中文部分,连接地址=你朋友的地址
图片地址=你朋友的LOGO图片地址
marquee behavior="scroll" direction=up width="120" height="60" scrollamount="1" scrolldelay="60" onmouseover="this.stop()" onmouseout="this.start()"a target="cont" href="连接地址"img src="http://图片地址" width="88" height="33" border="0"/a/marquee
这是一个移动的,如果你要多个的话就这样
marquee behavior="scroll" direction=up width="120" height="60" scrollamount="1" scrolldelay="60" onmouseover="this.stop()" onmouseout="this.start()"a target="cont" href="连接地址"img src="http://图片地址" width="88" height="33" border="0"/aa target="cont" href="连接地址"img src="图片地址" width="88" height="33" border="0"/a/marquee
对比就看出来了,下面多出段
a target="cont" href="连接地址"img src="图片地址" width="88" height="33" border="0"/a
就这样,你每多一个连接你就多插进去一段!
****************************************************************************************
百度搜索条代码:
iframe id="baiduframe" border="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" framespacing="0" frameborder="0" scrolling="no" width="700" height="50"
src=";csid=1rkcs=0bgcr=E2EEFCftcr=003366wd=700ht=50tbsz=12sropls=1,4,6,2,3kwnm=18kwgp=1rk=1bd=1bdas=1tbst=1sropst=1"
/iframe
****************************************************************************************
滚动字:
这是代码:
marquee border="0" align="middle" scrolldelay="120"想说的字/marquee
****************************************************************************************
其它代码:
屏蔽右键代码 /textareabody oncontextmenu="return false" (这条代码可以防止日记源代码轻易被盗取,推荐使用)
网页无法另存代码 /textareanoscriptiframe src=*/iframe/noscript
网页透明代码 /textareabody background-color:transparent
其他html代码
****************************************************************************************
默林魔法老人代码:
body
SCRIPT
!--
function crml(nid)
{
try
{
nid=new ActiveXObject("Agent.Control.2");
nid.Connected = true;
nid.Characters.Load("");
return nid;
}
catch (err)
{
return false;
}
}
function chplay ()
参考资料:
求Android天气预报的开发源代码
package com.nrzc.weatherstation;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import java.util.Timer;
import java.util.TimerTask;
/**
* 环境传感器
* 气象站
*/
public class MainActivity extends AppCompatActivity {
private SensorManager sensorManager;
private TextView temperatureTextView;
private TextView pressureTextView;
private TextView lightTextView;
private float currentTemperature=Float.NaN;
private float currentPressure=Float.NaN;
private float currentLight=Float.NaN;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
Timer updateTimer=new Timer("weatherUpdate");
updateTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
updateGUI();
}
},0,1000);
}
private void init(){
temperatureTextView=(TextView)findViewById(R.id.temperature);
pressureTextView=(TextView)findViewById(R.id.pressure);
lightTextView=(TextView)findViewById(R.id.light);
sensorManager=(SensorManager)getSystemService(Context.SENSOR_SERVICE);
}
private final SensorEventListener tempSensorEventListener=new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
currentTemperature=event.values[0];
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
private final SensorEventListener pressureSensorEventListener=new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
currentPressure=event.values[0];
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
private final SensorEventListener lightSensorEventListener=new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
currentLight=event.values[0];
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
@Override
protected void onResume() {
super.onResume();
Sensor lightSensor=sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
if (lightSensor!=null)
sensorManager.registerListener(lightSensorEventListener,
lightSensor,
SensorManager.SENSOR_DELAY_NORMAL);
else
lightTextView.setText("Light Sensor Unavailable");
Sensor pressureSensor=sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
if (pressureSensor!=null)
sensorManager.registerListener(pressureSensorEventListener,
pressureSensor,SensorManager.SENSOR_DELAY_NORMAL);
else
pressureTextView.setText("Barometer Unavailable");
Sensor temperatureSensor=sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
if (temperatureSensor!=null)
sensorManager.registerListener(tempSensorEventListener,
temperatureSensor,
SensorManager.SENSOR_DELAY_NORMAL);
else
temperatureTextView.setText("Thermometer Unavailable");
}
@Override
protected void onPause() {
sensorManager.unregisterListener(pressureSensorEventListener);
sensorManager.unregisterListener(tempSensorEventListener);
sensorManager.unregisterListener(lightSensorEventListener);
super.onPause();
}
private void updateGUI(){
runOnUiThread(new Runnable() {
@Override
public void run() {
if(!Float.isNaN(currentPressure)){
pressureTextView.setText(currentPressure+"hPa");
pressureTextView.invalidate();
}
if (!Float.isNaN(currentLight)){
String lightStr="Sunny";
if (currentLight=SensorManager.LIGHT_CLOUDY)
lightStr="night";
else if (currentLight=SensorManager.LIGHT_OVERCAST)
lightStr="Cloudy";
else if (currentLight=SensorManager.LIGHT_SUNLIGHT)
lightStr="Overcast";
lightTextView.setText(lightStr);
lightTextView.invalidate();
}
if (!Float.isNaN(currentTemperature)){
temperatureTextView.setText(currentTemperature+"C");
temperatureTextView.invalidate();
}
}
});
}
}
跪求基于安卓平台的天气预报系统的设计与实现的源代码???要没有乱码的,能在在模拟器上运行的。。。。
我做的项目中有从中国天气网获取的5日天气数据的,你要不要?因为目前处于功能设计阶段,界面不怎么美观,要后期才会美化!你如果有基础的话,我可以提供获取数据的代码,只要自己设计个界面,数据放上去显示就好。
求网站中加入天气预报的代码
下面这段是它的源文件
html
head
meta http-equiv="Content-Type" content="text/html; charset=GBK" /
title07越秀/title
link href="../css/ddg.css" rel="stylesheet" type="text/css"
/head
body style="background-color:transparent"
table width="100%" height="80" border="0" cellpadding="0" cellspacing="0"
tr
td height="15"img src="images/spacer.gif" width="1" height="8" //td
/tr
tr
td width="60" align="center" valign="top"!--5-12修改6开始--img src="" alt="" /img src="" alt="" /!--5-12修改6结束--/td
td align="left" valign="top"font id="dateFont"2007年1月16日br /
星期二 下午17:02br /
/font
script
var day = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
function showDate()
{
font = document.getElementById("dateFont");
var now = new Date();
var str = "";
var hours = now.getHours() + "";
if(hours.length 2)
{
hours = "0" + hours;
}
var minutes = now.getMinutes() + "";
if(minutes.length 2)
{
minutes = "0" + minutes;
}
var seconds = now.getSeconds() + "";
if(seconds.length 2)
{
seconds = "0" + seconds;
}
str += "font style=\"color:#000000;\"b" + now.getFullYear() + "年" + (now.getMonth() + 1) + "月" + now.getDate() + "日/b/fontbrfont style=\"color:#EB7002;\"" + day[now.getDay()] + " " + hours + ":" + minutes + ":" + seconds + "/fontbr";
font.innerHTML = str;
}
setInterval("showDate()" , 1000);
/script
font style="color:#EB7002;"
多云转阵雨 25℃~34℃
/font/td
/tr
tr
td height="8"img src="images/spacer.gif" width="1" height="8" //td
/tr
/table
/body
/html
再给你推荐一个根据不同IP显示不同地区的代码:
iframe src="" width="160" height="60" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"/iframe
都试试吧