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个左右,只发现了中国气象频道和腾讯天气城市代码参数特别: 暂且称 中国气象频道.腾讯天气使用的城市代码为 "新编码" 注:中国气象频 ...
随机推荐
- NetCat使用手册
简介: 在网络工具中有“瑞士军刀”美誉的NetCat(以下简称nc),在我们用了N年了至今仍是爱不释手.因为它短小精悍(这个用在它身上很适合,现在有人已经将其修改成大约10K左右,而且功能不减少) ...
- 利用RecyclerView CardView实现新闻卡片样式
引入的包: demo结构: 测试代码: News.java: package com.zzw.testcardview; import java.io.Serializable; public cla ...
- Win+R快速打开你的应用程序
参考自:http://blog.csdn.net/nothing0318/article/details/7179405 1:在你的磁盘任意位置创建一个文件夹,比如C:MyShortcut,然后将你的 ...
- 【转】Doscommand-操作Cmd的第三方控件
核心用法: Doscommand1.CommandLine := 'cmd /c' +[命令];Doscommand1.OutputLines :=Memo1.Lines;Doscommand1.Ex ...
- Linux之uboot分析与移植20160601
说一下uboot分析与移植: 1.下载.建立source insight工程.编译.烧写.如果无运行分析原因 tar xjf u-boot-2012.04.01.tar.bz2 cd u-boot-2 ...
- 1.python的第一步
学习python也有一段时间了,自认为基本算是入门了,想要写一些博客进行知识的汇总的时候.却发现不知道该从何说起了,因为python这门语言在语法上其实并不难,关键在于如何建立程序员的思维方式,而对于 ...
- [.NET] 打造防“狼”神器 :任务栏篇
@微微一笑:本文标题纯属自娱自乐. 隐藏任务栏效果图: 对比 说起来惭愧,上面这个隐藏任务栏功能,只是完成了我一半的预想.本想是可以选择性的隐藏任务栏上的某个TaskBarButton,但是Win7+ ...
- Socket与TcpClient的区别(转载)
Socket和TcpClient有什么区别 原文:http://wxwinter.spaces.live.com/blog/cns!C36588978AFC344A!322.entry 回答: &qu ...
- hive hwi使用
hwi(hive web interface)是hive命令行接口的补充. 使用方法: 1.配置: 在配置文件hive-site.xml 中,默认有hwi的配置 <property> &l ...
- [转]Squid中的日志出现TCP_CLIENT_REFRESH_MISS的问题排除
转自:http://www.php-oa.com/2008/07/15/tcp_client_refresh_miss.html 今天检查Squid发现大量的日志出现TCP_CLIENT_REFRES ...