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 ...
随机推荐
- Linux-C语言中gettimeofday()函数的使用方法(转载)
1.简介: 在C语言中可以使用函数gettimeofday()函数来得到时间.它的精度可以达到微妙 2.函数原型: #include<sys/time.h> int gettimeofda ...
- JVM内存管理 (转)
一.物理内存与虚拟内存1.物理内存 (1)RAM 所谓物理内存就是我们通常所说的RAM(随机存储器). (2)寄存器 在计算机中 ...
- Boost::Asio::Error的用法浅析
一般而言我们创建用于接收error的类型大多声明如下: boost::system::error_code error 我们用这个类型去接受在函数中产生的错误 如 socket.connect( en ...
- Android手机便携式wifi的使用及无线数据传输(主要针对XP系统)
适用条件: 1.可以上网的安卓系统2.2以上的智能手机,或有便携式wifi功能的安卓智能手机 2.有无线网卡的笔记本电脑或台式机(特别是XP系统) 测试手机:中兴U930 电脑:华硕K50系列笔记本 ...
- <摘录>详谈高性能TCP服务器的开发
对于开发一款高性能服务器程序,广大服务器开发人员在一直为之奋斗和努力.其中一个影响服务器的重要瓶颈就是服务器的网络处理模块.如果一款服务器程序不能及时的处理用户的数据.则服务器的上层业务逻辑再高效也是 ...
- xvfb 初步探究
有时候我们不关注程序是否有界面(比如自动化测试),只要程序在运行就可以了 很感谢 xvfb 这个工具给我们提供了相关的功能 比如在没有 X server 的机器上运行 gedit, 可以用下面的命令 ...
- CorePlot学习
阅读这篇文章,指出它在国外 原文地址:https://github.com/core-plot/core-plot/wiki/High-Level-Design-Overview 强烈推荐阅读该 ...
- Swift - 访问控制(private,internal,public)
在Swift语言中,访问修饰符有三种,分别为private,internal和public.同时,Swift对于访问权限的控制,不是基于类的,而是基于文件的.其区别如下: 1,private priv ...
- IT痴汉的工作现状18-思维定式
前阵子周权出差给我带回来一个净水器,是直接安装在水龙头上的,小巧方便.我依照安装说明一步一步组装好了,感觉说明书还是比較靠谱的,没有遇到意外.但我发现它的净水.原水的button好像是有问题.它的结构 ...
- HTML中Id和Name的区别
源地址:http://www.cnblogs.com/laodai/articles/2244215.html 在html中:name指的是用户名称,ID指的是用户注册是系统自动分配给用户的一个序列号 ...