Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLLocationManager - Calculate real time speed on iPhone

How can I calculate real time speed on device? I've googled a lot but all I got is to calculate distance and speed after completion of journey. Can I calculate speed at runtime?

Suggestions will be much appreciated.

Thanks in advance.

like image 826
Vineet Singh Avatar asked Aug 24 '12 09:08

Vineet Singh


1 Answers

here CLLocationManager class provide different field of location like, Latitude, Longitude,accuracy and speed.

i use CoreLocationController so for location update i call this bellow method you can get current speed in - (void)locationUpdate:(CLLocation *)location method like bellow

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

or otherwise bellow is 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 example from this link... http://www.vellios.com/2010/08/16/core-location-gps-tutorial/

i hope this help you... :)

like image 147
Paras Joshi Avatar answered Oct 10 '22 05:10

Paras Joshi