gpt4 book ai didi

android - Plugin.Geolocator 授权错误

转载 作者:搜寻专家 更新时间:2023-11-01 07:42:52 25 4
gpt4 key购买 nike

我想获取设备的 GPS 位置。我正在使用 Xamarin 的 GeolocatorPlugin 来获取我设备的经度和纬度。我的设备启用了 GPS。我已经向我的 android list 添加了权限,但我仍然收到错误消息:“发生地理定位错误:未经授权”我该如何解决这个问题?

try
{
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 50;

var position = await locator.GetPositionAsync();
entLocation.Text = position.Longitude.ToString() + "," + position.Latitude.ToString();
}
catch (Exception ex)
{
//will catch any general exception and set message in a string
string msg = ex.Message;
await DisplayAlert("error", msg, "ok");
}

最佳答案

将下面的代码放入您的 Android 项目中的 MainActivity.cs 中。

if(CheckSelfPermission(Manifest.Permission.AccessCoarseLocation) != (int)Permission.Granted)
{
RequestPermissions(new string[] { Manifest.Permission.AccessCoarseLocation, Manifest.Permission.AccessFineLocation }, 0);
}

关于android - Plugin.Geolocator 授权错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51869620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com