I have the following code in the .m file.
The code is to perform the following tasks:
- initialize the CLLocationManager class
- obtain the properties (Speed, Accuracy, Coordinates)
- convert these values to NSString
- log these values to the screen via use of NSLog
- set the values in the designated labels and then finally
- loop thru the code contained in method "locationUpdate".
The code provides an initial value for all these properties. However, the values are the same for every property (i.e. 2.7188880).
In addition, the code returns 0 for each property as I loop thru the method "locationUpdate".
Can anyone tell me the reason the code isn't returning values for the properties?
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 2.0
target: self
selector:@selector(locationUpdate)
userInfo: nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
NSString *spd = [[NSString alloc] initWithFormat:@"%f", speed];
NSString *crd = [[NSString alloc] initWithFormat:@"%f", coordinates];
NSString *drc = [[NSString alloc] initWithFormat:@"%f", direction];
NSString *acc = [[NSString alloc] initWithFormat:@"%f", accuracy];
NSString *desc = [locationManager description];
NSLog(@"Speed: %@", spd);
NSLog(@"Coordinates: %@", crd);
NSLog(@"Direction: %@", drc);
NSLog(@"Accuracy: %@", acc);
NSLog(@"Description: %@", desc);
Speedometer.text = spd;
CoordinatesLabel.text = crd;
DirectionLabel.text = drc;
AccuracyLabel.text = acc;
DescriptionLabel.text = desc;
}
- (void)locationUpdate {
NSString *desc = [locationManager description];
NSString *spd = [NSString stringWithFormat:@"%g", speed];
NSString *crd = [NSString stringWithFormat:@"%g", coordinates];
NSString *drc = [NSString stringWithFormat:@"%g", direction];
NSString *acc = [NSString stringWithFormat:@"%g", accuracy];
NSLog(@"Speed: %@", spd);
NSLog(@"Coordinates: %@", crd);
NSLog(@"Direction: %@", drc);
NSLog(@"Accuracy: %@", acc);
Speedometer.text = spd;
CoordinatesLabel.text = crd;
DirectionLabel.text = drc;
AccuracyLabel.text = acc;
DescriptionLabel.text = desc;
}