Frage

@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

War es hilfreich?

Lösung

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

Andere Tipps

keep this piece of code in viewDidLoad:

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

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top