韩弈风技术博客

为了应对人类无限制的贪婪,才要发动一次又一次得技术革命。QQ:29992379

wp7天气预报源代码(二序列化谷歌数据)公布源代码下载地址

在上一篇文章里已经介绍了这个应用

文章源地址:http://www.cnblogs.com/wildfeng/archive/2012/03/21/2410504.html

145236789

由于代码过多,和繁杂的前台页面效果代码,没办法在博文中说明白,还有很多网友要求我公布源代码项目。在文章的最下面我提供了源代码的下载地址。

作者QQ:29992379

这个天气预报用的是谷歌的API,我特意写了个工具类用来序列化返回的数据,本文中主要介绍这个工具类。

image

代码如下:

public static class GoogleWeatherHelper
    {

        /// <summary>
        /// 获取城市以及省
        /// </summary>
        /// <param name="xmlWeather">xml数据</param>
        /// <returns></returns>
        public static string GetCity(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_information").First();
            return forecast_information.Element("city").Attribute("data").Value;
        }
        /// <summary>
        /// 获取中文城市名称
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetPostalCode(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_information").First();
            return forecast_information.Element("postal_code").Attribute("data").Value;
        }
        /// <summary>
        /// 获取预报的日期
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetForecastDate(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_information").First();
            return forecast_information.Element("forecast_date").Attribute("data").Value;
        }
        /// <summary>
        /// 获取湿度
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetHumidity(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("current_conditions").First();
            return forecast_information.Element("humidity").Attribute("data").Value;
        }
        /// <summary>
        /// 获取风向
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetWindCondition(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("current_conditions").First();
            return forecast_information.Element("wind_condition").Attribute("data").Value;
        }
        /// <summary>
        /// 获取今天星期
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetTodayWeek(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").First();
            return forecast_information.Element("day_of_week").Attribute("data").Value;
        }
        /// <summary>
        /// 获取今天最低温度
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetTodayLow(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").First();
            return forecast_information.Element("low").Attribute("data").Value;
        }
        /// <summary>
        /// 获取今天最高温度
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetTodayHight(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").First();
            return forecast_information.Element("high").Attribute("data").Value;
        }
        /// <summary>
        /// 获取今天天气图标
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetTodayIcon(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").First();
            return ExtractFileName(forecast_information.Element("icon").Attribute("data").Value);
        }
        /// <summary>
        /// 获取今天天气情况
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetTodayCondition(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").First();
            return forecast_information.Element("condition").Attribute("data").Value;
        }
        /// <summary>
        /// 获取明天星期
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetTomorrowWeek(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(1);
            return forecast_information.Element("day_of_week").Attribute("data").Value;
        }
        /// <summary>
        /// 获取明天最低温度
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetTomorrowLow(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(1);
            return forecast_information.Element("low").Attribute("data").Value;
        }
        /// <summary>
        /// 获取明天最高温度
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetTomorrowHight(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(1);
            return forecast_information.Element("high").Attribute("data").Value;
        }
        /// <summary>
        /// 获取明天天气图标
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetTomorrowIcon(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(1);
            return ExtractFileName(forecast_information.Element("icon").Attribute("data").Value);
        }
        /// <summary>
        /// 获取明天天气情况
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetTomorrowCondition(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(1);
            return forecast_information.Element("condition").Attribute("data").Value;
        }
        /// <summary>
        /// 获取后天星期
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetHouTianWeek(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(2);
            return forecast_information.Element("day_of_week").Attribute("data").Value;
        }
        /// <summary>
        /// 获取后天最低温度
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetHouTianLow(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(2);
            return forecast_information.Element("low").Attribute("data").Value;
        }
        /// <summary>
        /// 获取后天最高温度
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetHouTianHight(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(2);
            return forecast_information.Element("high").Attribute("data").Value;
        }
        /// <summary>
        /// 获取后天天气图标
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetHouTianIcon(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(2);
            return ExtractFileName(forecast_information.Element("icon").Attribute("data").Value);
        }
        /// <summary>
        /// 获取后天天气情况
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetHouTianCondition(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(2);
            return forecast_information.Element("condition").Attribute("data").Value;
        }
        /// <summary>
        /// 获取大后天星期
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetDaHouTianWeek(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(3);
            return forecast_information.Element("day_of_week").Attribute("data").Value;
        }
        /// <summary>
        /// 获取大后天最低温度
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetDaHouTianLow(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(3);
            return forecast_information.Element("low").Attribute("data").Value;
        }
        /// <summary>
        /// 获取大后天最高温度
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetDaHouTianHight(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(3);
            return forecast_information.Element("high").Attribute("data").Value;
        }
        /// <summary>
        /// 获取大后天天气图标
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetDaHouTianIcon(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(3);
            return ExtractFileName(forecast_information.Element("icon").Attribute("data").Value);
        }
        /// <summary>
        /// 获取大后天天气情况
        /// </summary>
        /// <param name="xmlWeather"></param>
        /// <returns></returns>
        public static string GetDaHouTianCondition(XElement xmlWeather)
        {
            XElement forecast_information = xmlWeather.Descendants("forecast_conditions").ElementAt(3);
            return forecast_information.Element("condition").Attribute("data").Value;
        }

        private static string ExtractFileName(string fullFileName)
        {
            string str = fullFileName.Substring(fullFileName.LastIndexOf('/') + 1);
            return str.Substring(0, str.LastIndexOf('.')).Replace("cn_", "");
        }
    }

整个天气预报项目源代码的下载地址:http://download.csdn.net/detail/wildfeng04/4168595

在以后的博文里我会详细讲解这个应用UI方面的实现,毕竟这个应用亮点全在UI上面。我个人是这么理解的,因为功能代码不是很难,UI的效果比较炫。我用了Storyboard来实现了一些效果。

原文中地址:http://www.cnblogs.com/wildfeng/archive/2012/03/24/2415327.html

阅读更多
个人分类: windows phone 7
所属专栏: WindowsPhone开发
想对作者说点什么? 我来说一句

简易天气预报APP源码

2016年02月24日 8.77MB 下载

安卓天气预报源代码

2014年12月17日 1.45MB 下载

天气app(源码)

2017年10月05日 225KB 下载

安卓天气预报项目源代码

2016年10月09日 4.98MB 下载

天气预报源码(全)

2017年06月09日 28.93MB 下载

手机天气预报系统APP源码

2016年06月04日 6.19MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭