4

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?

Community
  • 1
  • 1
Code Hunter
  • 10,075
  • 23
  • 72
  • 102

2 Answers2

11

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);
}
Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
1

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

Abhishek Singh
  • 6,068
  • 1
  • 23
  • 25