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天气预报的更多相关文章

  1. wp实例开发精品文章源码推荐(8.20)

    热门源码推荐 WP7快递速查源码http://www.apkbus.com/android-115763-1-1.html WP7仿iphone气泡式短信界面 源码http://www.apkbus. ...

  2. 逆天通用水印支持Winform,WPF,Web,WP,Win10。支持位置选择(9个位置 ==》[X])

    常用技能:http://www.cnblogs.com/dunitian/p/4822808.html#skill 逆天博客:http://dnt.dkil.net 逆天通用水印扩展篇~新增剪贴板系列 ...

  3. wp已死,metro是罪魁祸首!

    1.这篇文章肯定会有类似这样的评论:“我就是喜欢wp,我就是喜欢metro,我就是软粉“等类似的信仰论者发表的评论. 2.2014年我写过一篇文章,windows phone如何才能在中国翻身? 我现 ...

  4. 关于 WP 开发中.xaml 与.xaml.cs 的关系

    今天我们先来看一下在WP8.1开发中最长见到的几个文件之间的关系.比较论证,在看这个问题之前我们简单看看.NET平台其他两个不同的框架: Windows Forms 先看看Window Forms中的 ...

  5. Android,ios,WP三大手机系统对比

    从前,我以为.一个手机系统只是一个系统的UI风格,没什么不同的.然而,在我混合使用这三个手机系统之后,才明白,一个手机系统远不只一个UI那么简单,而真的是可以称之为一个“生态”. 首先祭出三台经典设备 ...

  6. WEB前端工程师(实践)制作天气预报难度:简单

    需要准备:jQuery Bootstrap 天气预报API(本文中使用API可能会失效请灵活运用) CSS样式可以你自己去写这里只提出jQuery 请求数据和解析JSON数据 { "resu ...

  7. 天气预报API开发

    天气预报API开发 一.        寻觅篇 最近想要跟着视频练习一下利用API开发一个天气预报系统,就在网上找了一下可以用的API,结果好多都已经失效了... 1.       百度车联网天气预报 ...

  8. 搜狗输入法wp风格皮肤

    换了个nexus 发现输入法真的没有wp的好用 没办法,刚好搜狗输入法有定制皮肤的选项,所以自己做了个wp风格的输入法皮肤. 一点微小的工作 http://pan.baidu.com/s/1kVsHd ...

  9. 免费获取WP之类的开发者权限或免费使用Azure 2015-10-19

    上一次弄wp真机调试的时候,卡住了,这里讲一下怎么解决(http://www.cnblogs.com/dunitian/p/4870959.html) 进这个网址注册一下:https://www.dr ...

随机推荐

  1. 【thinking in java】读书笔记(一)

    近期開始读tij,好记性不如烂笔头,所以还是记录一下,方便以后查阅. 一.各种初始化问题: 方法重载的问题: 方法的重载,差别是靠传入方法的參数,而不是返回值.比方f(),假设是返回值的话,easy产 ...

  2. ORA-00942:表或视图不存在(低级错误)

    在好多时候.调试PL/SQL对象时会报.ORA-00942 看看错误原因吧: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamFjc29uX2JhaQ== ...

  3. Effective C++_笔记_条款02_尽量以const、enum、inline替换#define

    (整理自Effctive C++,转载请注明.整理者:华科小涛@http://www.cnblogs.com/hust-ghtao/) 这个条款或许改为“宁可以编译器替换预处理器”比较好,因为或许#d ...

  4. 解决Java compiler level does not match the version of the installed Java project facet.问题

    其实之前遇到过Java compiler level does not match the version of the installed Java project facet.这个问题,因为当时没 ...

  5. oracle 表连接 - hash join 哈希连接

    一. hash 连接(哈希连接)原理 指的是两个表连接时, 先利用两表中记录较少的表在内存中建立 hash 表, 然后扫描记录较多的表并探測 hash 表, 找出与 hash 表相匹配的行来得到结果集 ...

  6. ASP.NET - 在线编辑器(KindEditor)

    效果: 项目结构: 前端代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile=" ...

  7. [页面模板框架对比] Apache Tiles VS Sitemesh

    1. 原理对比 (1) Apache Tiles 顾名思义,Tile是瓷砖的意思,也就是说一个网页是由多个Tile组成的. 用户通过访问一个页面的Apache Tiles定义名,就可以访问一个由定义文 ...

  8. mysql READ-COMMITTED 模式下 行锁不会升级到表级锁

    mysql> select sn,id,info from s100 group by id; +-----+------+------+ | sn | id | info | +-----+- ...

  9. HDU3714 Error Curves (单峰函数)

    大意: 给你n个二次函数Si(x),F(x) = max{Si(x)} 求F(x)在[0,1000]上的最小值. S(x)=ax^2+bx+c       (0<=a<=100, |b|, ...

  10. ThinkPhp学习06

    原文:ThinkPhp学习06 一.简单学习修改用户信息模块 1.编写UserAction.class.php <?php class UserAction extends Action{ pu ...