Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to calculate speed in ios 7 using coreLocation framework

prior to iOS 7 i used to calculate speed as below

-(void)locationManager:(CLLocationManager *)manager 
   didUpdateToLocation:(CLLocation *)newLocation
          fromLocation:(CLLocation *)oldLocation
{

      double speed = newLocation.speed;
      NSLog(@"Speed of Device is %f",newLocation.speed); 

      // manual method
      if(oldLocation != nil)
      {
           CLLocationDistance distanceChange = [newLocation getDistanceFrom:oldLocation];
           NSTimeInterval sinceLastUpdate = [newLocation.timestamp 
           timeIntervalSinceDate:oldLocation.timestamp];
           double calculatedSpeed = distanceChange / sinceLastUpdate;

           NSLog(@"Speed of Device is %f",calculatedSpeed); 
     }  
 }  

since this method is deprecated ,. please suggest me another way to calculate speed using iOS7 using CoreLocation.

like image 742
Shaik Riyaz Avatar asked Dec 26 '22 14:12

Shaik Riyaz


1 Answers

You can do the following:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    CLLocation *loc = locations.lastObject;
    double speed = loc.speed;
    NSLog(@"%f", speed);
}
like image 92
Hannes Avatar answered Dec 28 '22 09:12

Hannes