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 ...
随机推荐
- Android 仿 窗帘效果 和 登录界面拖动效果 (Scroller类的应用) 附 2个DEMO及源码
在android学习中,动作交互是软件中重要的一部分,其中的Scroller就是提供了拖动效果的类,在网上,比如说一些Launcher实现滑屏都可以通过这个类去实现.下面要说的就是上次Scroller ...
- hdu 4687 带花树匹配
其实吧,思路挺简单的,只不过昨天刚学,还有一些东西不太了解,然后就23333333... 吃晚饭回来就A了,我是有多傻啊,这么题都A不掉,不能忍啊... 我们可以先求出哪些边是可能存在于最大匹配中的, ...
- BAPI总的数据库提交和回滚
BAPI事物中的数据提交和回滚必须通过调用SAP标准业务对象BAPI SERVICE(对象类型SAP0001)的BAPI方法bapiservic.transactioncommit和bapiservi ...
- Delphi中获取某类的祖先类及其所在单元名称(使用GetTypeData(PClass.ClassInfo)函数,并且该类是从TPersistent类的派生类才可以这么使用)
前几天在CSDN社区看到一篇<如何得到自身单元名称>的帖子,其中一位名为sdzeng网友给出了答案.受此启发,自己写了一个函数,用来获取指定类的所有祖先类的名称及其所在的单元名称. //参 ...
- OCA读书笔记(7) - 管理数据库存储结构
7.Managing Database Storage Structures 逻辑结构 数据库的存储结构有物理结构和逻辑结构组成的 物理结构:物理上,oracle是由一些操作系统文件组成的 SQL&g ...
- 代码写解压zip文件
最近项目中服务器方返回了zip文件类型的文件,在网上搜了好多资料做成一个Demo,这里用来详解一下. ZipArchive类来源于网络.还望多多交流. 1.首先添加libz.dylib框架 2.前往h ...
- CF 17B Hierarchy
Nick's company employed n people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinat ...
- xcode6 cocos2dx开玩笑git和github学习记录
1. git Xcode4开始,它一直Git作为一个内置的源代码控制(Source Control)工具,所以对于新项目的用途git要管理非常方便.在新建项目向导.可以直接选择Git作为源控制工具.项 ...
- (一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
(一)----使用HttpClient发送HTTP请求(通过get方法获取数据) 一.HTTP协议初探: HTTP(Hypertext Transfer Protocol)中文 “超文本传输协议”,是 ...
- Android 手势&触摸事件 MotionEvent
1.http://blog.csdn.net/omg_2012/article/details/7881443 这篇相当好啊 2.http://blog.csdn.net/android_tutor/ ...