C# 天气预报
问题描述:
使用C#做一个简易的天气预报系统
问题解决:
主要使用类如下:
WeatherLoc:包含常用的调用中国气象局天气情况接口
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WeatherReport.ServiceReference1; namespace WeatherReport
{
class WeatherLoc
{
//调用天气接口的类
private static WeatherWebServiceSoapClient ws= new WeatherWebServiceSoapClient("WeatherWebServiceSoap"
); public WeatherLoc()
{
}
//查看天气接口支持的省份
public String[] GetSupportProvince()
{
String[] supportProv = ws.getSupportProvince();
return supportProv;
}
//查看天气情况支持的城市
public String[] GetSupportCity(String province)
{
return ws.getSupportCity(province);
}
//查看指定城市的天气信息
public WeatherInfo GetWeatherInfo(String city)
{
String[] allInfo = ws.getWeatherbyCityName(city);
WeatherInfo weather = new WeatherInfo();
weather.Province = allInfo[];
weather.CityName = allInfo[];
weather.LastUpdateTime = allInfo[];
weather.Temperature = allInfo[];
weather.WeatherLive = allInfo[];
weather.LivingIndex = allInfo[];
weather.CityInfo = allInfo[]; FutureInfo[] future = new FutureInfo[]; //今天天气信息
future[].temp = allInfo[];
future[].overView = allInfo[];
future[].windDirection = allInfo[];
future[].tendencyBeg = allInfo[];
future[].tendencyEnd = allInfo[]; //明天的天气信息
future[].temp = allInfo[];
future[].overView = allInfo[];
future[].windDirection = allInfo[];
future[].tendencyBeg = allInfo[];
future[].tendencyEnd = allInfo[]; //后天的天气信息
future[].temp = allInfo[];
future[].overView = allInfo[];
future[].windDirection = allInfo[];
future[].tendencyBeg = allInfo[];
future[].tendencyEnd = allInfo[]; weather.FutureInfo = future; return weather;
}
}
}
WeatherInfo类:包含查询天气情况信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace WeatherReport
{
//未来三天天气情况结构体,C#中结构体默认访问权限是private,C++结构体默认访问权限为public
struct FutureInfo
{
public String temp; //温度
public String overView; //概况
public String windDirection; //风向和风力
public String tendencyBeg; //趋势开始图片
public String tendencyEnd; //趋势结束图片
}; class WeatherInfo
{
private String province; //省份
private String cityName; //城市名称
private String lastUpdateTime; //最后更新时间
private String temperature; //温度
private FutureInfo[] info; //未来三天天气情况
private String weatherLive; //现在天气实况
private String livingIndex; //生活指数
private String cityInfo; //城市介绍 public WeatherInfo()
{
cityName = "";
lastUpdateTime = "";
temperature = "";
info = new FutureInfo[];
weatherLive = "";
livingIndex = "";
cityInfo = "";
} public String Province
{
get
{
return province;
}
set
{
province = value;
}
} public FutureInfo[] FutureInfo
{
get
{
return info;
}
set
{
info = value;
}
} public String CityName
{
get
{
return cityName;
} set
{
cityName = value;
}
} public String LastUpdateTime
{
get
{
return lastUpdateTime;
}
set
{
lastUpdateTime = value;
}
} public String Temperature
{
get
{
return temperature;
}
set
{
temperature = value;
}
} public String WeatherLive
{
get
{
return weatherLive;
}
set
{
weatherLive = value;
}
} public String LivingIndex
{
get
{
return livingIndex;
}
set
{
livingIndex = value;
}
} public String CityInfo
{
get
{
return cityInfo;
}
set
{
cityInfo = value;
}
}
}
}
具体使用中国气象局天气接口方法如下:
(1)添加服务引用
(2)包含服务器引用接口
(3)接口使用,参考WeatherLoc类中接口调用
执行效果:
C# 天气预报的更多相关文章
- WEB前端工程师(实践)制作天气预报难度:简单
需要准备:jQuery Bootstrap 天气预报API(本文中使用API可能会失效请灵活运用) CSS样式可以你自己去写这里只提出jQuery 请求数据和解析JSON数据 { "resu ...
- 天气预报API开发
天气预报API开发 一. 寻觅篇 最近想要跟着视频练习一下利用API开发一个天气预报系统,就在网上找了一下可以用的API,结果好多都已经失效了... 1. 百度车联网天气预报 ...
- arcgis for flex全国地图天气预报的具体实现过程解析
系统架构是B/S,开发语言是flex,开发工具是myeclise或者flashbuild,通过调用百度提供的在线天气预报web api接口的方式来实现. 采用地图是ArcGIS全国地图,开发接口为ar ...
- 【代码笔记】iOS-获得徐家汇的天气预报
一,代码. //获得徐家汇的天气预报 -(void)getWeatherInfo{ NSError *error; NSURLRequest *request = [NSURLRequest requ ...
- webservice通信调用天气预报接口实例
转载:http://www.cnblogs.com/warrior4236/p/5668449.html 一:环境搭建 1:新建一个java project工程weatherInf 2:引入相应的ja ...
- 开源免费天气预报接口API以及全国所有地区代码!!(国家气象局提供) 【转】
国家气象局提供的天气预报接口 接口地址: http://www.weather.com.cn/data/sk/101010100.html http://www.weather.com.cn/data ...
- 常用Web Service汇总(天气预报、时刻表等)
现成的Web Service中有很多很好用的,比如天气预报,IP地址搜索,火车时刻表等等.本文汇总的一些常用Web Service,希望对大家有所帮助. AD: ================= ...
- 开源免费的天气预报接口API以及全国所有地区代码(国家气象局提供)
天气预报一直是各大网站的一个基本功能,最近小编也想在网站上弄一个,得瑟一下,在网络搜索了很久,终于找到了开源免费的天气预报接口API以及全国所有地区代码(国家气象局提供),具体如下: 国家气象局提供的 ...
- 天气预报API(三):免费接口测试(“旧编码”)
说明 我以参考文章为引子,自己测试并扩展,努力寻找更多的气象API... 本文所有测试均以青岛为例. 本文所列接口城市代码(cityid)参数都使用的 "旧编码": 全国城市代码列 ...
- 天气预报API(四):全国城市代码列表(“新编码”)
说明 天气预报API系列文章涉及到的天气网站10个左右,只发现了中国气象频道和腾讯天气城市代码参数特别: 暂且称 中国气象频道.腾讯天气使用的城市代码为 "新编码" 注:中国气象频 ...
随机推荐
- C#关于一个程序,只可以有一种实例的方法
方法一:使用线程互斥变量. 通过定义互斥变量来判断是否已运行实例.把program.cs文件里的Main()函数改为如下代码: 说明:程序中通过语句 System.Threading.Mutex ru ...
- SQL语句统计一段时间内的记录数
实际应用中经常需要统计单位时间的记录数: 一个小时: SELECT ),createdate,) AS 日期 ,DATEPART(hh,createdate) AS 小时,COUNT(*)AS 记录 ...
- Vue.js常见问题
1.Vuejs组件 vuejs构建组件使用 Vue.component('componentName',{ /*component*/ }): 这里注意一点,组件要先注册再使用,也就是说: Vue.c ...
- 学习c语言的第9天
#include <stdio.h> int main() { float sum=0,wage=0; int i=1; int num; printf("+++平均工资统计程序 ...
- linux iostat命令详解 磁盘操作监控工具
Linux系统中的 iostat是I/O statistics(输入/输出统计)的缩写,iostat工具将对系统的磁盘操作活动进行监视. 它的特点是汇报磁盘活动统计情况,同时也会汇报出CPU使用情况. ...
- 使用事务操作SQLite数据库
使用SQLiteDatabase的beginTransaction()方法可以开启一个事务,程序执行到endTransaction() 方法时会检查事务的标志是否为成功,如果程序执行到endTrans ...
- delphi android 中 Toast 的实现(老外写的UNIT)
unit Android.JNI.Toast; // Java bridge class imported by hand by Brian Long (http://blong.com)interf ...
- Hive启动时的棘手问题的处理
Hive是存在于Hadoop集群之上的数据仓库,作为大数据处理时的主要工具,对于大数据开发人员的重要性不言而喻.当然要使用Hive仓库的前提就是对于hive的安装,hive的安装是很简单的过程,主要关 ...
- 09-排序2 Insert or Merge
要点就是把排序每一步,判断一下是否和第二组数据相同,若相同则输出排序方法和下一次序列. According to Wikipedia: Insertion sort iterates, consumi ...
- 2.python的变量与赋值
首先,为何要使用变量这里就不再多说了,我这里就介绍一下变量的命令规则和变量赋值的内存行为. 1.变量的命名规则 变量其实通过一个标记调用内存中的值,而变量名就是这个标记的名称,但是万一这个标记已经被提 ...