我正在做一个应用程序。我正在使用 CLLocationManager 类来获取更新的位置纬度和经度详细信息。但我需要在单独的线程中使用这个 CLLocationManager。我编写了如下代码。
- (void)viewDidLoad
{
[NSThread detachNewThreadSelector:@selector(fetch) toTarget:self withObject:nil];
}
-(void)fetch
{
manager=[[CLLocationManager alloc]init];
manager.delegate=self;
manager.distanceFilter=kCLDistanceFilterNone;
manager.desiredAccuracy = kCLLocationAccuracyBest;
[manager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"%f",newLocation.coordinate.latitude);
lbl.text=[NSString stringWithFormat:@"%f",newLocation.coordinate.longitude];
}
.但是当我运行这段代码时,这个委托方法不会被触发。所以请指导我如何在单独的线程中获取位置更新。