You are storing just the last coordinates because you are initializing your array every time you get a new location, move the allocation line to another method (like viewDidLoad
) and erase that line in your didUpdateToLocation
.
- (void)viewDidLoad
{
[super viewDidLoad];
locationArray = [[NSMutableArray alloc]init];
//.... more code
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
//locationArray = [[NSMutableArray alloc]init]; //This line doesn't go here
[locationArray addObject:currentLocation];
speed = (int) currentLocation.speed * 3.6;
self.labelSpeed.text = [NSString stringWithFormat:@"%d Km/h",speed];
NSLog(@"%@", [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude]);
NSLog(@"%@", [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude]);
}
}