【问题标题】:not get location using Plugin.Geolocator in xamarin无法在 xamarin 中使用 Plugin.Geolocator 获取位置
【发布时间】: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


【解决方案1】:

据我所知,唯一可能发生索引超出范围异常的合理位置是在某些外部代码中。

可能对GeoPos 的赋值有异常导致的效果...

【讨论】:

  • 即使我评论 // GeoPos = position.Latitude.ToString();还是抛出异常
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-12
  • 1970-01-01
  • 2018-10-09
  • 1970-01-01
相关资源
最近更新 更多