微软自带的地图很简单
第一步引用地图xmlns:Map="using:Windows.UI.Xaml.Controls.Maps"
这段代码写在<Page>
然后在Grid
用 Map 来得到 MapControl
<Map:MapControl />
尝试运行
提示 警告:未指定MapServiceToken
在功能选位置功能
要获得位置需要权限
为了获得位置,写一个按钮点击获得位置
MainPage.xaml.cs
//需要using Windows.Devices.Geolocation; var access = await Windows.Devices.Geolocation.Geolocator.RequestAccessAsync(); switch (access) { case GeolocationAccessStatus.Unspecified: //定位未开启提示是否跳转到 设置 页面 return; case GeolocationAccessStatus.Allowed: //允许获取 break; case GeolocationAccessStatus.Denied: //不允许获取位置信息时 给予提示 然后根据情况选择是否跳转到 设置 界面 await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings://privacy/location")); return; default: break; } var gt = new Geolocator(); var position = await gt.GetGeopositionAsync(); //以前的position.Coordinate.Latitude 方法在UWP中已经过时,不再推荐使用 //var latiude = position.Coordinate.Latitude; map.Center = position.Coordinate.Point; map.ZoomLevel = 10;
因为 map.Center 说的是 Geopoint,王陈染大神说的是position = await gt.GetGeopositionAsync();
类型是Geoposition,结果错误是出现了
无法将类型“Windows.Devices.Geolocation.Geoposition”隐式转换为“Windows.Devices.Geolocation.Geopoint” appButtonBar
正确的代码 map.Center = position.Coordinate.Point;
点击就把地图中心设置在用户位置

原文链接: http://blog.lindexi.com/post/win10-UWP-%E6%98%BE%E7%A4%BA%E5%9C%B0%E5%9B%BE
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。 欢迎转载、使用、重新发布,但务必保留文章署名 林德熙 (包含链接: https://blog.lindexi.com ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请与我 联系。