Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I calculate my speed with an iPhone? [duplicate]

Tags:

ios

iphone

Possible Duplicate:
How to calculate speed of our car using iphone

How can I calculate my speed with an iPhone? For example, I might want to measure the speed of my car when driving. How can I implement this?

like image 489
Code Hunter Avatar asked Dec 16 '22 00:12

Code Hunter


2 Answers

Try something like this:

- (id) init
{
    self = [super init];
    if (self != nil) {
        self.manager = [[CLLocationManager alloc] init];
        self.manager.delegate = self;
        [self.manager startUpdatingLocation];
    }
    return self;
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"Speed = %f", newLocation.speed);
}
like image 178
Ashley Mills Avatar answered Jan 22 '23 22:01

Ashley Mills


1>You can use GPS Use the location services to get the latitude and longitude at a particular point of time and the you can get the same after a certain period of time say t.You can get the distance traveled from Latitude and longitude and divide it by the taken to get the speed

See the Apple GPS Doc

2>You can use Accelerometer if you start from a halt, you should be able to calculate the distance you travel based off the acceleration over time of the device.

See the Apple Accelerometer Doc

like image 20
Abhishek Singh Avatar answered Jan 22 '23 20:01

Abhishek Singh