- (id) init
{
self = [super init];
if (self != nil)
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
}
return self;
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"Location: %@", [newLocation description]);
[self.delegate locationUpdate:newLocation];
}
- (void)locationManager:(CLLocationManager *)managerdidFailWithError:(NSError *)error;
{
[self.delegate locationError:error];
NSLog(@"Error Error: %@",[error description]);
}
Эти функции делегата будут вызываться в классе MyCLConrolleer.m.
Выделите этот класс в классе ViewController следующим образом.
locationController = [[MyCLController alloc] init];
locationController.delegate = self;
[locationController.locationManager startUpdatingLocation];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
showCurrentLocation = NO;
Функции делегатов в классе View Controller
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
[self getLocationNameWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude];
}