ios - CLLocationManagerDelegate 方法未更新

标签 ios delegates location cllocationmanager

@property (nonatomic,strong) CLLocationManager *locManager;

这是我设置管理器的地方:

-(void) viewDidAppear:(BOOL)animated
{
    self.locManager = [[CLLocationManager alloc] init];
    [_locManager setDelegate:self];
    [_locManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [_locManager setPausesLocationUpdatesAutomatically:NO];
    [_locManager setDistanceFilter:1.0];
    [_locManager startUpdatingLocation];
}

这是我的委托(delegate)方法:

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
    int degrees = newLocation.coordinate.latitude;
    double decimal = fabs(newLocation.coordinate.latitude - degrees);
    int minutes = decimal * 60;
    double seconds = decimal * 3600 - minutes * 60;
    NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
                     degrees, minutes, seconds];
    latLabel.text = lat;
    degrees = newLocation.coordinate.longitude;
    decimal = fabs(newLocation.coordinate.longitude - degrees);
    minutes = decimal * 60;
    seconds = decimal * 3600 - minutes * 60;
    NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
                       degrees, minutes, seconds];
    lonLabel.text = longt;
}

该方法在启动时被调用三次,然后再也没有调用过。 预先感谢您

最佳答案

上述方法已弃用。 请使用这个委托(delegate)

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

    latitude                                        = location.coordinate.latitude;
    longitude                                       = location.coordinate.longitude;

   [locationManager stopUpdatingLocation];
    locationManager                                 = nil;
}

关于ios - CLLocationManagerDelegate 方法未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22602323/

相关文章:

android - 创建与 native 库 .net Maui 的绑定(bind)

ios - 一个 Sprite 能知道它什么时候在现场吗?

objective-c - QTCaptureOutput.delegate captureOutput :didOutputVideoFrame:. ..从未调用过

kotlin - 如何结合 kotlin 委托(delegate)属性 : observable, vetoable 和 "by map"?

c# - 有人可以向我解释一下事件到底是什么以及与委托(delegate)有什么区别吗?

iphone - 延迟位置更新 iOS 6

ios - 在 Swift 4.2 中生成二维码和制作 PDF 文件后内存泄漏

JavaME : ProximityListener destroyed/unregisterd after one use?

c# - 媒体播放器 c# 从网络播放

ios - Codility 编程测试和 Objective-C 语法