kCLErrorDomain Code = 8”该操作无法完成。 [英] kCLErrorDomain Code=8 "The operation couldn’t be completed.

查看:151
本文介绍了kCLErrorDomain Code = 8”该操作无法完成。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Am开始进行反向地理编码,并且_geocoder实例变量被初始化为OK,但是没有数据传递给_placemark对象。这是错误日志:

Am starting to do reverse geocoding, and the _geocoder instance variable gets initialized OK, but no data gets passed to the _placemark object. Here is the error log:

2013-12-16 14:00:12.040 MyLocations[10555:70b] *** Going to geocode
2013-12-16 14:00:12.041 MyLocations[10555:70b] *** Found placemarks: (null), error: Error Domain=kCLErrorDomain Code=8 "The operation couldn’t be completed. (kCLErrorDomain error 8.)"

Am假设正在调用locationManager:didFailWithError:方法,但是不明白错误代码。

Am assuming that the locationManager:didFailWithError: method is getting called, but don't understand the error code.

这是CurrentLocationViewController.m的代码。

Here is the code for CurrentLocationViewController.m

#import "CurrentLocationViewController.h"

@interface CurrentLocationViewController ()

@end

@implementation CurrentLocationViewController {
    CLLocationManager *_locationManager;
    CLLocation *_location;

    BOOL _updatingLocation;
    NSError *_lastLocationError;

    CLGeocoder *_geocoder;
    CLPlacemark *_placemark;
    BOOL _performingReverseGeocoding;
    NSError *_lastGeocodingError;
}

-(id)initWithCoder:(NSCoder *)aDecoder
{
    if((self = [super initWithCoder:aDecoder])) {
        _locationManager = [[CLLocationManager alloc] init];
        _geocoder = [[CLGeocoder alloc] init];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self updateLabels];
    [self configureGetButton];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)getLocation:(id)sender
{
    if(_updatingLocation) {
        [self stopLocationManager];
    } else {
        _location = nil;
        _lastLocationError = nil;

        [self startLocationManager];
    }
    [self updateLabels];
    [self configureGetButton];

}

#pragma mark - CLLocationManagerDelegate

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"didFailWithError %@", error);

    if (error.code == kCLErrorLocationUnknown) {
        return;
    }

    [self stopLocationManager];
    _lastLocationError = error;

    [self updateLabels];
    [self configureGetButton];


}

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    CLLocation *newLocation = [locations lastObject];

    if ([newLocation.timestamp timeIntervalSinceNow] <- 5.0) {
        return;
    }

    if (newLocation.horizontalAccuracy < 0) {
        return;
    }

    if (!_performingReverseGeocoding) {
        NSLog(@"*** Going to geocode");

        _performingReverseGeocoding = YES;

        [_geocoder reverseGeocodeLocation:_location completionHandler:^(NSArray *placemarks, NSError *error) {
            NSLog(@"*** Found placemarks: %@, error: %@", placemarks, error);

            _lastGeocodingError = error;
            if (error == nil && [placemarks count] > 0) {
                _placemark = [placemarks lastObject];
            } else {
                _placemark = nil;
            }

            _performingReverseGeocoding = NO;
            [self updateLabels];
        }];

    }
}

-(void)updateLabels
{
    if (_location != nil) {
        self.latitudeLabel.text = [NSString stringWithFormat:@"%.8f", _location.coordinate.latitude];
        self.longitudeLabel.text = [NSString stringWithFormat:@"%.8f", _location.coordinate.longitude];
        self.tagButton.hidden = NO;
        self.messageLabel.text = @"";
    } else {
        self.latitudeLabel.text = @"";
        self.longitudeLabel.text = @"";
        self.addressLabel.text = @"";
        self.tagButton.hidden = YES;

        NSString *statusMessage;
        if (_lastLocationError == nil) {
            if ([_lastLocationError.domain isEqualToString:kCLErrorDomain] && _lastLocationError.code == kCLErrorDenied) {
                statusMessage = @"Location Services Disabled";
            } else {
                statusMessage = @"Error Getting Location";
            }
        } else if (![CLLocationManager locationServicesEnabled]) {
            statusMessage = @"Location Services Disabled";
        } else if (_updatingLocation) {
            statusMessage = @"Searching...";
        } else {
            statusMessage = @"Press the Button to Start";
        }

        self.messageLabel.text = statusMessage;
        }
}

-(void)configureGetButton
{
    if (_updatingLocation) {
        [self.getButton setTitle:@"Stop"
                        forState:UIControlStateNormal];
    } else {
        [self.getButton setTitle:@"Get My Location"
                        forState:UIControlStateNormal];
    }
}

-(void)startLocationManager
{
    if ([CLLocationManager locationServicesEnabled]) {
        _locationManager.delegate = self;
        _locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
        [_locationManager startUpdatingLocation];
        _updatingLocation = YES;
    }
}

-(void)stopLocationManager
{
    if (_updatingLocation) {
        [_locationManager stopUpdatingLocation];
        _locationManager.delegate = nil;
        _updatingLocation = NO;
    }
}

@end


推荐答案

kCLErrorDomain错误8表示Apple geoloc服务器对提供的位置一无所知。进行反向地址解析时:lat / long没有地址匹配,进行正向地址解析时:未知地址链接到lat / long

kCLErrorDomain error 8 means Apple geoloc servers know nothing about the provided location. When doing reverse geocoding: lat/long has no address match, when forward geocoding: the address is not known to link to lat/long

这篇关于kCLErrorDomain Code = 8”该操作无法完成。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆