Этот метод вызывается всякий раз, когда ваше устройство iOS перемещается за установленный вами фильтр расстояния.Например, если вы установите его на
[self.locationManager setDistanceFilter:kCLDistanceFilterNone];
Метод будет вызываться при каждом перемещении устройства.
Примером кода будет поиск координат, а затем присвоение этих значений меткам
- (void)viewDidLoad{
[super viewDidLoad];
altitudeLabel.text = @"0 ft";
ftOrM = YES;
// Note: we are using Core Location directly to get the user location updates.
// We could normally use MKMapView's user location update delegation but this does not work in
// the background. Plus we want "kCLLocationAccuracyBestForNavigation" which gives us a better accuracy.
//
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self; // Tells the location manager to send updates to this object
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
[self.locationManager setDistanceFilter:kCLDistanceFilterNone];
[self.locationManager startUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation: (CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation {
tLatitude = [NSString stringWithFormat:@"%3.5f", newLocation.coordinate.latitude];
tLongitude = [NSString stringWithFormat:@"%3.5f", newLocation.coordinate.longitude];
/* the following returns 0 */
float distanceMeters;
float distanceFeet;
if (ftOrM == YES) {
distanceMeters = newLocation.altitude;
distanceFeet = distanceMeters * 3.2808399;
tAltitude = [NSString stringWithFormat:@"%.02f ft", distanceFeet];
altitudeLabel.text = tAltitude;
}
else {
tAltitude = [NSString stringWithFormat:@"%.02f m", newLocation.altitude];
NSLog(@"Altitude:");
NSLog(@"%@", tAltitude);
altitudeLabel.text = tAltitude;
NSLog(@"Altitude:");
NSLog(@"%@", tAltitude);
}
//[manager stopUpdatingLocation];
}