wp天气预报
ak
url http://developer.baidu.com/map/index.php?title=car
后台cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Runtime.Serialization.Json;
using System.Text;
using Windows.Data.Json;
using Windows.Devices.Geolocation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Web.Http; // “空白页”项模板在 http://go.microsoft.com/fwlink/?LinkId=234238 上提供 namespace App3
{
/// <summary>
/// 可独立使用或用于导航至 Frame 内部的空白页。
/// </summary>
public sealed partial class MainPage : Page
{
string ak = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
public MainPage()
{
this.InitializeComponent();
}
/// <summary>
/// 导航到该页面的时候被执行
/// </summary>
/// <param name="e"></param>
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
Load.IsActive = true;
var cityName = await GetCityName();
var data = await GetWeatherByCityName(cityName);
var viewModel = new MainPageViewModel();
viewModel.CityName = cityName;
viewModel.IndexInfos = data.results[0].index;
viewModel.WeatherInfos = data.results[0].weather_data;
this.DataContext = viewModel;
Load.IsActive = false; } private async System.Threading.Tasks.Task<weatherDate> GetWeatherByCityName(string cityName)
{
var apiAddress = string.Format("http://api.map.baidu.com/telematics/v3/weather?location={0}&output=json&ak={1}", cityName, ak);
HttpClient client = new HttpClient();
var json = await client.GetStringAsync(new Uri(apiAddress));
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(weatherDate));
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
{
return serializer.ReadObject(ms) as weatherDate;
}
} private static async System.Threading.Tasks.Task<string> GetCityName()
{
Geolocator o = new Geolocator();
var geo = await o.GetGeopositionAsync();
var position = geo.Coordinate.Point.Position;
var apiAddress = string.Format("http://api.map.baidu.com/geocoder/v2/?ak=XXXXXXXXXXXXXXXXXXXXXX&output=json&location={0},{1}", position.Latitude, position.Longitude);
HttpClient client = new HttpClient();
var json = await client.GetStringAsync(new Uri(apiAddress));
var jsonObject = JsonObject.Parse(json);
var cityName = jsonObject["result"].GetObject()["addressComponent"].GetObject()["city"].GetString();
return cityName;
}
}
public class MainPageViewModel
{
public string CityName { get; set; }
public IList<indexList> IndexInfos { get; set; }
public IList<weather_dataList> WeatherInfos { get; set; }
}
public class weatherDate
{
public int error { get; set; }
public string status { get; set; }
public string date { get; set; }
public List<resultsList> results { get; set; }
}
public class resultsList
{
public string currentCity { get; set; }
public string pm25 { get; set; }
public List<indexList> index { get; set; }
public List<weather_dataList> weather_data { get; set; }
}
public class indexList
{
public string title { get; set; }
public string zs { get; set; }
public string tipt { get; set; }
public string des { get; set; }
}
public class weather_dataList
{
public string date { get; set; }
public string dayPictureUrl { get; set; }
public string nightPictureUrl { get; set; }
public string weather { get; set; }
public string wind { get; set; }
public string temperature { get; set; }
} }
前台xaml
<Page
x:Class="App3.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App3"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid>
<Hub>
<HubSection x:Uid="index1">
<HubSection.Background>
<ImageBrush ImageSource="/Assets/aa.jpg" Stretch="UniformToFill"/>
</HubSection.Background>
<DataTemplate>
<Grid Width="350" Height="500" >
<TextBlock Text="{Binding CityName}" Foreground="Red" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="22" />
</Grid>
</DataTemplate>
</HubSection>
<HubSection x:Uid="index2">
<DataTemplate>
<ListView ItemsSource="{Binding WeatherInfos}">
<ListView.ItemTemplate>
<DataTemplate>
<Border Width="360" BorderThickness="2" BorderBrush="#FF2996AE">
<StackPanel>
<TextBlock Text="{Binding date}" FontSize="25"/>
<TextBlock Text="{Binding weather}" FontSize="30"/>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding dayPictureUrl}"></Image>
</StackPanel>
<TextBlock Text="{Binding wind}" FontSize="25"/>
<TextBlock Text="{Binding temperature}" FontSize="30"/>
</StackPanel>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DataTemplate>
</HubSection>
<HubSection x:Uid="index3">
<DataTemplate>
<ListView ItemsSource="{Binding IndexInfos}">
<ListView.ItemTemplate>
<DataTemplate>
<Border>
<StackPanel>
<TextBlock Text="{Binding tipt}" FontSize="30"/>
<TextBlock Text="{Binding zs}" FontSize="30"/>
<TextBlock Text="{Binding des}" FontSize="30" TextWrapping="Wrap"/>
</StackPanel>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DataTemplate>
</HubSection>
</Hub>
<ProgressRing Height="100" Width="100" x:Name="Load"/>
</Grid>
</Page>
wp天气预报的更多相关文章
- wp实例开发精品文章源码推荐(8.20)
热门源码推荐 WP7快递速查源码http://www.apkbus.com/android-115763-1-1.html WP7仿iphone气泡式短信界面 源码http://www.apkbus. ...
- 逆天通用水印支持Winform,WPF,Web,WP,Win10。支持位置选择(9个位置 ==》[X])
常用技能:http://www.cnblogs.com/dunitian/p/4822808.html#skill 逆天博客:http://dnt.dkil.net 逆天通用水印扩展篇~新增剪贴板系列 ...
- wp已死,metro是罪魁祸首!
1.这篇文章肯定会有类似这样的评论:“我就是喜欢wp,我就是喜欢metro,我就是软粉“等类似的信仰论者发表的评论. 2.2014年我写过一篇文章,windows phone如何才能在中国翻身? 我现 ...
- 关于 WP 开发中.xaml 与.xaml.cs 的关系
今天我们先来看一下在WP8.1开发中最长见到的几个文件之间的关系.比较论证,在看这个问题之前我们简单看看.NET平台其他两个不同的框架: Windows Forms 先看看Window Forms中的 ...
- Android,ios,WP三大手机系统对比
从前,我以为.一个手机系统只是一个系统的UI风格,没什么不同的.然而,在我混合使用这三个手机系统之后,才明白,一个手机系统远不只一个UI那么简单,而真的是可以称之为一个“生态”. 首先祭出三台经典设备 ...
- WEB前端工程师(实践)制作天气预报难度:简单
需要准备:jQuery Bootstrap 天气预报API(本文中使用API可能会失效请灵活运用) CSS样式可以你自己去写这里只提出jQuery 请求数据和解析JSON数据 { "resu ...
- 天气预报API开发
天气预报API开发 一. 寻觅篇 最近想要跟着视频练习一下利用API开发一个天气预报系统,就在网上找了一下可以用的API,结果好多都已经失效了... 1. 百度车联网天气预报 ...
- 搜狗输入法wp风格皮肤
换了个nexus 发现输入法真的没有wp的好用 没办法,刚好搜狗输入法有定制皮肤的选项,所以自己做了个wp风格的输入法皮肤. 一点微小的工作 http://pan.baidu.com/s/1kVsHd ...
- 免费获取WP之类的开发者权限或免费使用Azure 2015-10-19
上一次弄wp真机调试的时候,卡住了,这里讲一下怎么解决(http://www.cnblogs.com/dunitian/p/4870959.html) 进这个网址注册一下:https://www.dr ...
随机推荐
- Swift - 在界面上生成81个随机红,灰色圆点(SpriteKit游戏开发)
下面是生成一个“围住神经猫”游戏的初始场景: 1,界面下方会生成9*9共81个圆点,同时圆点内部添加文本标签显示索引 2,默认圆点为灰色,每行随机取两个点变为红色 3,奇数行和偶数行有一定的错位,错位 ...
- JSP的学习(6)——九大隐式对象及其out对象
本篇将介绍JSP中的九大隐式对象,并重点介绍其中的out对象. 我们在之前的博客<JSP的学习(1)——基础知识与底层原理>一文中已经知道,JSP最终要被翻译和转换成Servlet,在转换 ...
- [置顶] 手把手教你iOS消息推送证书生成以及Push消息
iOS推送消息是许多iOS应用都具备的功能,今天在给应用加推送功能,在生成证书的过程中,发生了各种令人蛋痛的事.下面就把步骤拿出来分享下: iOS消息推送的工作机制可以简单的用下图来概括: Provi ...
- vmware 中 ubuntu linux 安装vmware tools
参考官方方法 http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&ex ...
- Swift - 继承UIView实现自定义可视化组件(附记分牌样例)
在iOS开发中,如果创建一个自定义的组件通常可以通过继承UIView来实现.下面以一个记分牌组件为例,演示了组件的创建和使用,以及枚举.协议等相关知识的学习. 效果图如下: 组件代码:Score ...
- MySQL :: MySQL 5.0 Reference Manual :: 14.4 The MEMORY (HEAP) Storage Engine
MySQL :: MySQL 5.0 Reference Manual :: 14.4 The MEMORY (HEAP) Storage Engine The MEMORY (HEAP) Stora ...
- hdu 4055 Number String(有点思维的DP)
Number String Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 新手推荐:IIS+PHP+MYSQL环境配置教程
本文介绍刚开始接触php的朋友如何为自己的服务器配置php环境 首先我们要的工具: 1.IIS:这个当然是不能少的了,用系统自带的就好了,这里就不教大家怎么装了. 2.PHP:php-5.2.0-wi ...
- Github Atom
码代码新神器-Github Atom 周末闲着没事,逛论坛发现了一个新的编辑器,由github发布的Atom编辑器.瞬间被吸引了,所以就去尝试着折腾了一下,后来发现这个编辑器确实很不错,他的特点就 ...
- java学习笔记05--字符串 .
java学习笔记05--字符串 . 一.String类 由字符所组成的一串文字符号被称之为字符串.在java中字符串不仅仅是字符数组,而且是String类的一个实例,可以使用String类来构建. 字 ...