C#UWP地理位置,访问被拒绝 [英] C# UWP Geolocation, access denied

查看:90
本文介绍了C#UWP地理位置,访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有人.

我正在尝试获取C#UWP应用程序中的当前用户位置.

I am trying to get current user's location in C# UWP application.

var geoLocator = new Geolocator();
geoLocator.DesiredAccuracy = PositionAccuracy.High;
var accessStatus = await Geolocator.RequestAccessAsync();
var pos = await geoLocator.GetGeopositionAsync();
var latitude = pos.Coordinate.Point.Position.Latitude;
var longitude = pos.Coordinate.Point.Position.Longitude;

但是我得到了错误:

mscorlib.ni.dll中发生类型为'System.UnauthorizedAccessException'的异常,但未在用户代码中处理WinRT信息:您的应用没有访问位置数据的权限.确保已在应用清单中定义了ID_CAP_LOCATION,并且在手机上已通过检查设置">位置"来打开位置.附加信息:访问被拒绝.

在Package.appxmanifest中,我检查了以下项目:互联网(客户端和服务器)-已选中,互联网(客户端)-已选中位置-已选中.

In Package.appxmanifest I have these items checked: Internet (Client & Server) - checked, Internet (Client) - checked, Location - checked.

如何在本地计算机上设置权限?

How can I set permission in local machine?

推荐答案

我解决了这个问题.在Windows 10中,在位置"隐私设置中,我的位置服务未打开.所以我打开了它,现在它可以工作了.

I solved this issue. In Windows 10, in Location privacy settings my Location services wasn't on. So I turned it on, and now it is working.

这篇关于C#UWP地理位置,访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆