C# 无法使用xamarin中的Plugin.geologitor获取位置

C# 无法使用xamarin中的Plugin.geologitor获取位置,c#,xamarin,xamarin.forms,geolocation,C#,Xamarin,Xamarin.forms,Geolocation,我想做一个简单的应用程序,让我知道我的当前位置,我正在使用Geolocator插件来查询我的位置,但当我调用GetPositionAsync()方法时,它会抛出一个异常错误,该应用程序有权访问我手机中的位置。这是我的代码: try { if ( locator.IsGeolocationEnabled == false ) { await App.Current.MainPage.Display

我想做一个简单的应用程序,让我知道我的当前位置,我正在使用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");
        }
它会将我发送到捕获异常并显示此错误:


谢谢大家的帮助

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


如果对var position=WAIT locator.GetLastKnownLocationAsync()进行更改,则对
GeoPos
的赋值可能会产生异常影响…

;工作正常,但这样做很好??即使我注释//GeoPos=position.Latitude.ToString();仍然抛出异常