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?
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);
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With