简体   繁体   English

iOS 8 MapKit位置无法启动

[英]ios 8 MapKit location will not start

Since ios 8 I cannot get the mapkit to start in the debugger. 从ios 8开始,我无法在调试器中启动mapkit。 I'm using XCode Version 6.1 (6A1052d) on Mac OS X 10.9.5. 我在Mac OS X 10.9.5上使用XCode版本6.1(6A1052d)。 And yes I've read and googled several suggestions but I can't get it to work. 是的,我已阅读并搜索了一些建议,但无法正常工作。

I have added these lines in my myproject-info.plist; 我在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>

This is how I try to initialice LocationManager in my first view viewDidLoad method; 这就是我尝试在第一个视图viewDidLoad方法中初始化LocationManager的方法;

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

Later, in another controller i programatically add a mapkit view like this; 后来,在另一个控制器中,我以编程方式添加了一个像这样的mapkit视图;

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

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

But I always get this in the output console; 但是我总是在输出控制台中得到它。

2014-11-22 19:14:36.777 vind4r[1019:16660] Trying to start MapKit location updates without prompting for location authorization. 2014-11-22 19:14:36.777 vind4r [1019:16660]尝试启动MapKit位置更新而没有提示位置授权。 Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first. 必须首先调用-[CLLocationManager requestWhenInUseAuthorization]或-[CLLocationManager requestAlwaysAuthorization]。

Any ideas someone? 有任何想法吗?

Kind regards, Jan Gifvars Stockholm 亲切的问候,Jan Gifvars斯德哥尔摩

Try to move 尝试移动

mapView.showsUserLocation = YES;

To the -locationManager:didChangeAuthorizationStatus: -locationManager:didChangeAuthorizationStatus:

There you can check status for >= kCLAuthorizationStatusAuthorized and set showsUserLocation there: 您可以在此处检查> = kCLAuthorizationStatusAuthorized的状态,并在那里设置showsUserLocation

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

Declare 宣布

CLLocationManager *locationManager

in your .h file 在您的.h文件中

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

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