【问题标题】:ios 8 MapKit location will not startios 8 MapKit 位置无法启动
【发布时间】:2015-01-20 18:14:41
【问题描述】:

从 ios 8 开始,我无法在调试器中启动 mapkit。我正在使用 XCode 版本 6.1 (6A1052d) 在 Mac OS X 10.9.5 上。是的,我已经阅读并搜索了一些建议,但我无法让它发挥作用。

我已在 myproject-info.plist 中添加了这些行;

</array>
<key>NSLocationUsageDescription</key>
<string>I need location</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>I need location</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>I need location</string>
</dict>

这就是我尝试在我的第一个视图 viewDidLoad 方法中初始化 LocationManager 的方式;

CLLocationManager *locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; 
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager requestAlwaysAuthorization];
[locationManager startUpdatingLocation];

稍后,在另一个控制器中,我以编程方式添加这样的 mapkit 视图;

mapView = [[MKMapView alloc] initWithFrame:self.view.frame];
[self.view addSubview:mapView];

[mapView setDelegate:self];
mapView.showsUserLocation = YES;

但我总是在输出控制台中得到这个;

2014-11-22 19:14:36.777 vind4r[1019:16660] 尝试在不提示位置授权的情况下启动 MapKit 位置更新。必须先调用 -[CLLocationManager requestWhenInUseAuthorization] 或 -[CLLocationManager requestAlwaysAuthorization]。

有人有什么想法吗?

亲切的问候, 扬·吉瓦斯 斯德哥尔摩

【问题讨论】:

    标签: ios mapkit


    【解决方案1】:

    声明

    CLLocationManager *locationManager
    

    在您的 .h 文件中

    【讨论】:

      【解决方案2】:

      尝试移动

      mapView.showsUserLocation = YES;
      

      -locationManager:didChangeAuthorizationStatus:

      您可以在那里检查 >= kCLAuthorizationStatusAuthorized 的状态并在那里设置showsUserLocation

      - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
          if (status >= kCLAuthorizationStatusAuthorized) {
              self.mapView.showsUserLocation = YES;
          }
      }
      

      【讨论】:

      • 谢谢,我已经尝试了你的建议。现在差不多了,即我可以看到询问允许/不允许的对话框。但是,一旦我的控制器从 viewDidLoad 方法返回并呈现视图,对话框就会消失,嗯,为什么对话框不是模态的或什么?我从来没有以 ... didChangeAuthorizationStatus: 方法结束。
      • 抱歉,我搞砸了本地声明的 locationmanager。感谢您的时间和帮助!
      猜你喜欢
      • 2014-09-03
      • 1970-01-01
      • 2014-12-10
      • 2014-09-17
      • 2014-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-25
      相关资源
      最近更新 更多