首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >无法在xamarin中使用Plugin.Geolocator获取位置

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

Stack Overflow用户
提问于 2018-06-10 08:35:55
回答 1查看 190关注 0票数 0

我想做一个简单的应用程序,给我带来我的当前位置,我正在使用地理定位器插件来查询我的位置,但当我调用GetPositionAsync()方法时,它抛出一个异常错误,该应用程序有权访问我手机中的位置。下面是我的代码:

代码语言:javascript
复制
  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

感谢大家的帮助!

EN

回答 1

Stack Overflow用户

发布于 2018-06-10 08:41:59

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

也许对GeoPos的赋值有一个异常导致的效果...

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50779664

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档