【发布时间】:2018-06-10 00:35:55
【问题描述】:
我想做一个简单的应用程序来显示我当前的位置,我正在使用 Geolocator 插件来查询我的位置,但是当我调用 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
感谢大家的帮助!
【问题讨论】:
-
如果更改 var 位置 = await locator.GetLastKnownLocationAsync();可以,但那样做可以吗??
标签: c# xamarin xamarin.forms geolocation