Reputation: 2935
I am using following code to update location after every 0.1 second -
- (void)viewDidLoad
{
[super viewDidLoad];
CLController = [[CoreLocationController alloc] init];
CLController.delegate = self;
// set auto update timer
currentTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self
selector:@selector(updatestart) userInfo:nil repeats:YES];
}
-(void)updatestart
{
[CLController.locMgr startUpdatingLocation];
}
And then I am trying to calculate speed using
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
[locMgr stopUpdatingLocation];
NSLog(@"%f",newLocation.speed);
}
I am getting speed in meter/sec but after some time the process slows down and even when I stop traveling the speed is being calculated.
What I want is to get accurate speed and show alert if speed is above 12km/hr.
Is there any other approach which I can use to find the same?
Thanks..
Upvotes: 1
Views: 1722
Reputation: 113747
Starting and stopping the location manager like that isn't the way to do it. You can't force it to give more location updates. Leave it running and average the location updates over time. To get the best accuracy, use kCLLocationAccuracyBestForNavigation
for the location manager's desiredAccuracy
.
Upvotes: 3