Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLLocationManager giving wrong location updates

I am working on a tracking app, which needs to display the tracking path on map. When I start updating location and does not move the device after the installation, the locationManagar reports wrong location updates,

enter image description here

I am drawing a route based on location points reported,

Also when user is driving in a vehicle at high speed on straight road, it shows glitches like this as well,

How can I ignore these erroneous location updates.

You can download the app here and test yourself

like image 436
zaheer Avatar asked Apr 06 '26 13:04

zaheer


1 Answers

Have a look at Horizontal Accuracy check this to make sure you have an accurate location. For example below 10meters or below zero:

    // test that the horizontal accuracy does not indicate an invalid measurement
    if (lastLocation.horizontalAccuracy < 0)
        return;

And make sure you have a new location because it will return the last one default:

// test the age of the location measurement to determine if the measurement is cached
        // in most cases you will not want to rely on cached measurements
        NSTimeInterval locationAge = -[lastLocation.timestamp timeIntervalSinceNow];
        if (locationAge > 5.0)
            return;

Also make sure you set the right desiredAccuracy on the CLLocationManager. For example:

_manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
like image 83
Sjoerd Perfors Avatar answered Apr 09 '26 02:04

Sjoerd Perfors