ios - 我的 xamarin.ios 项目中的 CLLocation 为 Null

标签 ios iphone xamarin xamarin.ios cllocationmanager

我正在使用 CLLocationManager 在我的 xamarin.ios 项目中获取 GPS 坐标,它在昨天之前工作正常,今天它因抛出此 this 而崩溃此行出现空异常

double lat = locationManager.Location.Coordinate.Latitude;

以下是我的代码

    if (CLLocationManager.LocationServicesEnabled) {
                    double lat = locationManager.Location.Coordinate.Latitude;
                    double lon = locationManager.Location.Coordinate.Longitude;

                    CLLocationCoordinate2D mapCenter = new CLLocationCoordinate2D (lat, lon);
}

我已经删除了应用程序并重新安装,我已经重新启动了 xamarin studio 但没有运气,任何人都可以帮助我

最佳答案

在检查 CLLocationManager.LocationServicesEnabled 时,我还会检查:

CLLocationManager.Status == CLAuthorizationStatus.AuthorizedAlways

如果用户拒绝使用他们的位置。查看枚举 CLAuthorizationStatus对于您的应用程序可能使用的所有不同情况,例如AuthorizedWhenInUse。还要检查设置中的权限,看看你的应用是否被允许

关于ios - 我的 xamarin.ios 项目中的 CLLocation 为 Null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31384655/

相关文章:

iOS 7后台上传和POST请求

iphone - 如果不满足条件,则在 init 中销毁 UIView

php - 可以设置 iAMP 吗?

ios - xamarin iOS : How to show the audio amplitude of the voice when recording

ios - 如何访问我项目的资源文件夹中所有文件的列表?

ios - 线程 1 : EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) Relm

ios - constraintsWithVisualFormat 为所有 View 设置相同的 Y 位置

javascript - 触摸事件在 IOS 7 Iphone 中不起作用

iphone - 检测哪个应用程序正在 iOs 设备上运行并返回描述应用程序类别的数据

xamarin - Xamarin 标签中可单击的部分文本