我想做一个简单的应用程序,给我带来我的当前位置,我正在使用地理定位器插件来查询我的位置,但当我调用GetPositionAsync()方法时,它抛出一个异常错误,该应用程序有权访问我手机中的位置。下面是我的代码:
try
{
if ( locator.IsGeolocationEnabled == false )
{
await App.Current.MainPage.DisplayAlert("Error", "location is not enable", "aceptar");
return;
}
if( locator.IsGeolocationAvailable == false)
{
await App.Current.MainPage.DisplayAlert("Error", "location is not aviable", "aceptar");
return;
}
var position = await locator.GetPositionAsync(TimeSpan.MaxValue);
GeoPos = position.Latitude.ToString();
}
catch (Exception ex)
{
await App.Current.MainPage.DisplayAlert("Error", ex.ToString(), "aceptar");
}
它会将我发送到一个捕获异常,并显示此错误:error message
感谢大家的帮助!
发布于 2018-06-10 08:41:59
据我所知,发生索引超出范围异常的唯一合理位置是在一些外部代码中。
也许对GeoPos
的赋值有一个异常导致的效果...
https://stackoverflow.com/questions/50779664
复制相似问题