首页 > ios > iOS关于定位的认识Error Domain=kCLErrorDomain Code=2

iOS关于定位的认识Error Domain=kCLErrorDomain Code=2

  今天遇到意见很郁闷的事情,原来运行好好的代码,在今天的运行中发现了一个问题,定位出现的问题:报错:error domain=kclerrordomain code=2 the operation couldn’t be completed. (kclerrordomain error 2.)
  这是什么情况啊?下面的这段代码有问题吗?我以前运行的好好的。

_geocoder = [[CLGeocoder alloc] init];
        [_geocoder reverseGeocodeLocation: location completionHandler:^(NSArray *array, NSError *error) {
            if (!error) {
                if (array.count > 0) {
                    CLPlacemark *placemark = [array objectAtIndex:0];
                    _countryCode = placemark.ISOcountryCode;
                    NSLog(@"placemark = %@",placemark);
                }
            }
            else{
                NSLog(@"location error = %@",error);
            }
            _geocoder = nil;
        }];

  我去stackoverflow上面查查帖子,竟然有的说是因为请求的次数太多了的缘故。
  原回答:
  I believe the reason is the following:
  Apple’s geocoder does not answer every request in the same way. Instead, the first requests from a certain device are answered quickly, but if the device has sent say 100 requests or more, the answers arrive slower and slower or requests are not answered at all, which might cause your error.
When you reload the view controller, this simply takes time, and the geocoding server is more willing to answer again. Essentially, you cannot do anything about it, since the geocoder sever wants to protect itself from being overloaded by requests from a single device. You simply had to limit the number of requests that you send there.
  BTW: The docs say “you should not send more than one geocoding request per minute”.
  我当时很郁闷,我以前怎么运行的好好的?

  后来查到了原因:因为没有网络,唉,再无网络环境下面是不是地理逆向编码有问题了?这个有可能。研究至此吧,以后遇见了再说说。

  1. 还没有评论
评论提交中, 请稍候...

留言


可以使用的标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Trackbacks & Pingbacks ( 0 )
  1. 还没有 trackbacks