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 ...
随机推荐
- SQL逆向工程
话说有个现成的SQL数据库,四十来张表,每张表多的几十的字段,少的十几个字段.老板说为了下一步大家好好利用这个数据库中的数据,让你研究一下该数据库中的所有的表和字段之间的联系.这是一个什么性质的工作, ...
- 微软HR泄露的asp.net面试题
1.面向对象的思想主要包括什么? 2.什么是ASP.net中的用户控件? 3.什么叫应用程序域?什么是受管制的代码?什么是强类型系统?什么是装箱和拆箱?什么是重载? 4.列举一下你所了解的XML技术及 ...
- Servlet的学习(一)
初识Servlet Servlet是一门专门用于开发动态web资源的技术,Sun公司在其API中提供了一个Servlet接口(当然,我们不会去直接实现这个接口,而是去继承其实现类会更好),因此,狭义的 ...
- DLP显示单元(威创)
品牌:威创型号:E-SX675生产商:广东威创视讯科技股份有限公司1.生厂商简介(1)生产商概述广东威创视讯科技股份有限公司(简称威创)成立于2002年,专业从事大屏幕拼接显示产品及其解决方案的研发. ...
- [概念] js的函数节流和throttle和debounce详解
js的函数节流和throttle和debounce详解:同样是实现了一个功能,可能有的效率高,有的效率低,这种现象在高耗能的执行过程中区分就比较明显.本章节一个比较常用的提高性能的方式,通常叫做&qu ...
- uva 10131 Is Bigger Smarter?(DAG最长路)
题目连接:10131 - Is Bigger Smarter? 题目大意:给出n只大象的属性, 包括重量w, 智商s, 现在要求找到一个连续的序列, 要求每只大象的重量比前一只的大, 智商却要小, 输 ...
- ubuntu10.10 tftp安装,配置,测试
ubuntu10.10 tftp安装,配置,测试 成于坚持,败于止步 虽然ubuntu/centos/redhat都是linux,但是内核其中存在一定的修改,所以对于tftp服务器的安装存在不同的命令 ...
- JSTL分割字符 fn:split()
<%@ page language="java" contentType="text/html; charset=UTF-8"%><%@ ta ...
- hdu2159 Fate 二维背包
#include <cstring> #include <string> #include <cstdio> #include <cmath> #inc ...
- cronjob不跑得原因
能是环境的不同,能够在cronjob中加个env > /tmp/env.output查看 应用要同一时候输出标准错误合标准输出到一个文件能够&> /tmp/t