Hunter Rawson
Hunter Rawson

Reputation: 19

CLLocationManagerDelegate method is not updating

@property (nonatomic,strong) CLLocationManager *locManager;

This is where I set up the manager:

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

This is my delegate method:

- (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;
}

The method gets called three times upon launching and then never again. Thank you in advance

Upvotes: 0

Views: 211

Answers (3)

Gajendra Rawat
Gajendra Rawat

Reputation: 3663

Use this method:

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    location_updated = [locations lastObject];    
    NSLog(@"updated coordinate are %@",location_updated);
}

This method:

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation;

...has been deprecated in iOS 6.0

Upvotes: 0

Rose
Rose

Reputation: 437

The above method is deprecated. Please use this delegate

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

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

   [locationManager stopUpdatingLocation];
    locationManager                                 = nil;
}

Upvotes: 1

Rajesh
Rajesh

Reputation: 10424

keep this piece of code in viewDidLoad:

self.locManager = [[CLLocationManager alloc] init];

Upvotes: 0

Related Questions