标签:
首先在界面中加入一个textblock控件以显示信息
1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System.Linq; 5 using System.Runtime.InteropServices.WindowsRuntime; 6 using Windows.Foundation; 7 using Windows.Foundation.Collections; 8 using Windows.UI.Xaml; 9 using Windows.UI.Xaml.Controls; 10 using Windows.UI.Xaml.Controls.Primitives; 11 using Windows.UI.Xaml.Data; 12 using Windows.UI.Xaml.Input; 13 using Windows.UI.Xaml.Media; 14 using Windows.UI.Xaml.Navigation; 15 using Windows.Devices.Geolocation; 16 17 // “空白页”项模板在 http://go.microsoft.com/fwlink/?LinkId=391641 上有介绍 18 19 namespace Weather 20 { 21 /// <summary> 22 /// 可用于自身或导航至 Frame 内部的空白页。 23 /// </summary> 24 public sealed partial class MainPage : Page 25 { 26 public MainPage() 27 { 28 this.InitializeComponent(); 29 30 this.NavigationCacheMode = NavigationCacheMode.Required; 31 } 32 33 /// <summary> 34 /// 在此页将要在 Frame 中显示时进行调用。 35 /// </summary> 36 /// <param name="e">描述如何访问此页的事件数据。 37 /// 此参数通常用于配置页。</param> 38 protected override async void OnNavigatedTo(NavigationEventArgs e) 39 { 40 //获取手机所在位置 41 var geolocator = new Geolocator(); 42 43 var geoPosition = await geolocator.GetGeopositionAsync(); 44 //当前手机所在经纬度位置 45 var position = geoPosition.Coordinate.Point.Position; 46 47 txtLocation.Text = string.Format("经度:{0};纬度:{1}", position.Longitude, position.Latitude); 48 } 49 } 50 }
标签:
原文地址:http://www.cnblogs.com/Liqiongyu/p/5087056.html