CLLocationManager - Calculate Real-Time Speed ​​on iPhone

How to calculate the real-time speed on the device? I google a lot, but all I have is to calculate the distance and speed after completing the journey. Is it possible to calculate the speed at runtime?

Suggestions will be highly appreciated.

Thanks in advance.

+6
source share
2 answers

here the CLLocationManager class provides another location field, such as latitude, longitude, accuracy and speed.

I use CoreLocationController , so to update the location I call this method below you can get the current speed in - (void) locationUpdate: (CLLocation *) location , as shown below.

  - (void)locationUpdate:(CLLocation *)location { NSString *currentspeed = [NSString stringWithFormat:@"SPEED: %f", [location speed]]; } 

or else, the delegate method

 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSLog(@"in update to location"); NSString *currentspeed = [NSString stringWithFormat:@"SPEED: %f", [newLocation speed]]; } 

also you can get an example from this link ... http://www.vellios.com/2010/08/16/core-location-gps-tutorial/

Hope this helps you ... :)

+2
source

There is a CLLocationManagerDelegate delegate that adds it to the controller header file.

Initialize the location manager and set the delegate where you implement the delegation method for the location manager, for example

 self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; // send loc updates to current class 

and you can write a method in your class

 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSLog(@"Location Speed: %f", newLocation.speed); } 

So that you also receive your location updates in the way indicated above with speed, and it will work as often as possible.

0
source

Source: https://habr.com/ru/post/923642/


All Articles