微软自带的地图功能简单易用,可以通过以下步骤在uwp应用中实现。
首先,在
<page></page>
xmlns:Map="using:Windows.UI.Xaml.Controls.Maps"
接下来,在
Grid
MapControl
<mapcontrol></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
map.Center = position.Coordinate.Point;
点击按钮后,地图中心将设置为用户的当前位置。

参考资料:https://www.php.cn/link/751943b07f0b9c3540b8b533a6ca43f2
以上就是win10 UWP 显示地图的详细内容,更多请关注php中文网其它相关文章!
Windows激活工具是正版认证的激活工具,永久激活,一键解决windows许可证即将过期。可激活win7系统、win8.1系统、win10系统、win11系统。下载后先看完视频激活教程,再进行操作,100%激活成功。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号