Я получаю широту, долготу, высоту, точность, скорость от службы определения местоположения.
Я хочу обновлять всю эту информацию каждые 30 секунд. Для этого я использовал NSTimer:
[NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(locationUpdate:) userInfo:nil repeats:YES];
, который я положил в методе viewDidLoad
. Он показывает вывод в первый раз, но во второй раз, когда таймер вызывает это, он показывает эту ошибку:
2011-08-02 13:17:00.141 CoreLocationAssign[1120:207] This is location <__NSCFTimer: 0x4b200a0>
2011-08-02 13:17:00.142 CoreLocationAssign[1120:207] -[__NSCFTimer coordinate]: unrecognized selector sent to instance 0x4b200a0
2011-08-02 13:17:00.144 CoreLocationAssign[1120:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFTimer coordinate]: unrecognized selector sent to instance 0x4b200a0'
*** Call stack at first throw:
Код ниже:
MyCLController.h
@implementation MyCLController
@synthesize locationManager;
@synthesize delegate;
- (id) init{
if (self!=nil) {
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
[self.locationManager startUpdatingLocation];
}
return self;
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
//NSLog(@"Location: %@", [newLocation description]);
[self.delegate locationUpdate:newLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
// NSLog(@"Error: %@", [error description]);
[self.delegate locationError:error];
}
- (void)dealloc {
[self.locationManager release];
[super dealloc];
}
CoreLoactionController.h
- (void)viewDidLoad {
locationController = [[MyCLController alloc] init];
locationController.delegate = self;
[locationController.locationManager startUpdatingLocation];
[NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(locationUpdate:) userInfo:nil repeats:YES];
[super viewDidLoad];
}
- (void)locationUpdate:(CLLocation *)location {
locationLable.text = [location description];
CLLocationCoordinate2D coordinate = [location coordinate];
NSLog(@"This is location %@",[location description]);
NSLog(@"Lattitude = %@",[NSString stringWithFormat:@"%f", coordinate.latitude]);
NSLog(@"Langitude = %@",[NSString stringWithFormat:@"%f", coordinate.longitude]);
NSLog(@"Altitude = %@",[NSString stringWithFormat:@"%gm", location.altitude]);
NSLog(@"horizontalAccuracy = %@",[NSString stringWithFormat:@"%gm", location.horizontalAccuracy]);
NSLog(@"verticalAccuracy = %@",[NSString stringWithFormat:@"%gm", location.verticalAccuracy]);
NSLog(@"Speed = %@",[NSString stringWithFormat:@"%gm", location.speed]);
}
Как я могу решить эту проблему? Я хочу обновлять местоположение каждые 30 секунд.