UWP学习笔记之Location
MainPage.Xaml中:
- <Page
- x:Class="Location.MainPage"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="using:Location"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d"
- xmlns:Maps="using:Windows.UI.Xaml.Controls.Maps"> <!--这是引用的Maps-->
- <Page.BottomAppBar>
- <AppBar IsOpen="True" IsSticky="True">
- <StackPanel Orientation="Horizontal">
- <AppBarButton Name="Location" Icon="Map" Label="Location" Click="Location_Click"/>
- </StackPanel>
- </AppBar>
- </Page.BottomAppBar>
- <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
- <Maps:MapControl Name="Display"/> <!--地图控件-->
- </Grid>
- </Page>
PageMain.appxmanifese中:
- <Capabilities>
- <Capability Name="internetClient" />
- <!-- MSDN:https://msdn.microsoft.com/library/windows/apps/br211430 -->
- <DeviceCapability Name="location" /> <!-- 允许获取设备地理位置 -->
- </Capabilities>
MainPage.Xaml.cs中:
- //地图定位
- private async void Location_Click(object sender, RoutedEventArgs e)
- {
- Windows.Devices.Geolocation.Geopoint position = await Library.Position(); //获得设备位置
- DependencyObject marker = Library.Marker(); //画小圆点
- Display.Children.Add(marker);
- Windows.UI.Xaml.Controls.Maps.MapControl.SetLocation(marker, position); //设置小圆点位置
- //MSDN:https://msdn.microsoft.com/en-us/library/windows.ui.xaml.controls.maps.mapcontrol.setnormalizedanchorpoint.aspx
- Windows.UI.Xaml.Controls.Maps.MapControl.SetNormalizedAnchorPoint(marker, new Point(0.5, 0.5));
- //话说这个看不懂。。。求大神解救
- Display.ZoomLevel = 12; //缩放比例
- Display.Center = position;
- }
参考教程:https://comentsys.wordpress.com/2015/05/31/windows-10-universal-windows-platform-location/
强迫自己看英文吧。。。
打算做个晴天钟的Uwp。。。其实还是很好玩的。。。
//明天电钢就到了。。。等我爽个礼拜。。。

浙公网安备 33010602011771号