Problem finding speed when using CLLocationManager

I am developing a speedometer application on an iPhone. I used CLLocationManager (GPS) to measure vehicle speed. But I do not get the exact speed. I tried all the filtering methods given in various discussions using stackoverflow. But I do not get any improvements. From time to time, the speed reaches a higher value (> 400 km / h).

I don’t know what went wrong. Please offer me any code to get the exact speed.

Thanks in advance,

I followed the thread stack discussion below

Speed ​​measurement via iPhone SDK

Optimization of CLLocationManager / CoreLocation to quickly get data points on iPhone

CLLocation Speed

Why is my CLLocation speed so inaccurate?

Currently, I have implemented the following code:

//locationManager declaration in ViewDidLoad

locManager=[[CLLocationManager alloc]init];
locManager.delegate =self;
[locManager startUpdatingLocation];           


- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

    NSTimeInterval locationAge = abs([newLocation.timestamp timeIntervalSinceNow]);

    if (locationAge > 5.0) return;
    if (newLocation.speed < 0 || newLocation.horizontalAccuracy < 0) return;
    if ((newLocation.horizontalAccuracy < (oldLocation.horizontalAccuracy - 10.0)) || (newLocation.horizontalAccuracy < 50.0)|| (newLocation.horizontalAccuracy <= 150.0))
    {
        if(oldLocation != nil)
        {
            CLLocationDistance distanceChange = [newLocation distanceFromLocation:oldLocation];

            NSTimeInterval sinceLastUpdate = [newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp];


            double calculatedSpeed;
            calculatedSpeed = (distanceChange / sinceLastUpdate)*3.6;   // to convert the speed into kmph.

        }       
    }

}
+3
source share
1 answer

Even if you don’t like the built-in speed, just scroll your own.

Speed ​​is distance over time, right?

If you have two CLLocations, you can do:

CLLocationDistance distance = [aLocation distanceFromLocation:bLocation];

distanceis now a float of the distance between the two points, in meters. And those two CLLocationsalso have properties timestamp, right? Contains NSDate objects. Well...

NSTimeInterval timediff = [aDate timeIntervalSinceDate:bDate];

timediff - difference in seconds.

Thus, your average speed between these points in meters per second distanceexceeds timediff. Now you can calculate the instantaneous speed as accurately as the frequency with which you receive location updates.

, , , speed CLLocation, . , , .

, . 1609,344 . 3600 .

: , GPS, , . GPS, , , -, , , .

+4

All Articles