0

In Swift or Objective-C, we can easily create a CLLocationmanager and start tracking our position. We can also set a distanceFilter, which defines the minimum distance (measured in meters) a device must move horizontally before an update event is generated. My Swift code:

override func viewDidLoad() {
    super.viewDidLoad()

    manager = CLLocationManager()
    manager.delegate = self
    manager.distanceFilter = 10
    manager.desiredAccuracy = kCLLocationAccuracyBest
    manager.startUpdatingLocation()
}

But in certain circumstances, with a lower gps accuracy (ie in woods, tunnels, between high buildings...) incorrect spikes are generated. The CLLocationManager lacks a property or method to define a maximum distance for an update in order to clean up this sort of spikes.

Right now, I'm handling the max distance myself storing usable locations into a seperate array:

var myLocations: [CLLocation] = []

func calculateDistanceBetweenTwoLocations(start:CLLocation,destination:CLLocation) {
    var distanceInMeters = start.distanceFromLocation(destination)      
    if distanceInMeters < 20 {
        myLocations.append(destination)
    }
} 

Is there a more accurate way?

Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85

1 Answers1

1

What you're looking for is a Data cleansing method applied for GPS data.

If you have some time ahead, you can read this PDF about it

Some of the ways explained is to take 5 concurrents points and make sure it's part of a cluster with a certain precision parameter. If not, remove the points that are out.

Dean
  • 1,512
  • 13
  • 28