UWP学习笔记之Location

 

 

MainPage.Xaml中:

[html] view plain copy
 
  1. <Page  
  2.     x:Class="Location.MainPage"  
  3.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  4.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
  5.     xmlns:local="using:Location"  
  6.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
  7.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
  8.     mc:Ignorable="d"  
  9.     xmlns:Maps="using:Windows.UI.Xaml.Controls.Maps"<!--这是引用的Maps-->  
  10.     <Page.BottomAppBar>  
  11.         <AppBar IsOpen="True" IsSticky="True">   
  12.             <StackPanel Orientation="Horizontal">  
  13.                 <AppBarButton Name="Location" Icon="Map" Label="Location" Click="Location_Click"/>  
  14.             </StackPanel>  
  15.         </AppBar>  
  16.     </Page.BottomAppBar>  
  17.     <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">  
  18.         <Maps:MapControl Name="Display"/> <!--地图控件-->  
  19.     </Grid>  
  20. </Page>  

 

PageMain.appxmanifese中:

 

[html] view plain copy
 
  1. <Capabilities>  
  2.     <Capability Name="internetClient" />  
  3.       
  4.     <!-- MSDN:https://msdn.microsoft.com/library/windows/apps/br211430 -->  
  5.     <DeviceCapability Name="location" /> <!-- 允许获取设备地理位置 -->  
  6.       
  7.  </Capabilities>  

 

 

MainPage.Xaml.cs中:


[csharp] view plain copy
 
  1. //地图定位  
  2.     private async void Location_Click(object sender, RoutedEventArgs e)  
  3.         {  
  4.             Windows.Devices.Geolocation.Geopoint position = await Library.Position(); //获得设备位置  
  5.             DependencyObject marker = Library.Marker(); //画小圆点  
  6.             Display.Children.Add(marker);   
  7.             Windows.UI.Xaml.Controls.Maps.MapControl.SetLocation(marker, position); //设置小圆点位置  
  8.               
  9.     //MSDN:https://msdn.microsoft.com/en-us/library/windows.ui.xaml.controls.maps.mapcontrol.setnormalizedanchorpoint.aspx  
  10.             Windows.UI.Xaml.Controls.Maps.MapControl.SetNormalizedAnchorPoint(marker, new Point(0.5, 0.5));   
  11.     //话说这个看不懂。。。求大神解救  
  12.               
  13.             Display.ZoomLevel = 12; //缩放比例  
  14.             Display.Center = position;  
  15.         }  




参考教程:https://comentsys.wordpress.com/2015/05/31/windows-10-universal-windows-platform-location/

 


强迫自己看英文吧。。。

 

打算做个晴天钟的Uwp。。。其实还是很好玩的。。。

 

//明天电钢就到了。。。等我爽个礼拜。。。

posted @ 2016-09-28 18:24  天涯海角路  阅读(145)  评论(0)    收藏  举报