简体   繁体   English

在xamarin中使用Plugin.Geolocator无法获得位置

[英]not get location using Plugin.Geolocator in xamarin

I want to do a simple app that brings me my current location, I am using Geolocator plug in to consult my location but it throw me an exception error when i call the method GetPositionAsync(), the app have permission to access location in my phone. 我想做一个简单的应用程序来获取我的当前位置,我正在使用Geolocator插件查询我的位置,但是当我调用方法GetPositionAsync()时,它抛出了异常错误,该应用程序有权访问我手机中的位置。 there is my code: 有我的代码:

  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");
        }

its send me to a catch exception and display this error: error message 其将我发送到catch异常并显示此错误: 错误消息

thanks to all for your help! 感谢大家的帮助!

The only reasonable place that an index out of range exception can occur is in some external code, as far as I can tell. 据我所知,索引超出范围异常可能发生的唯一合理位置是在某些外部代码中。

Maybe the assignment to GeoPos has an exception causing effect... 也许分配给GeoPos的异常导致了效果...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM