iOS: Track user is driving in background
<p>My goal is to know when the user is traveling even if the app is killed or in the background. So I implemented this:</p>

<pre><code>let locationManager = CLLocationManager()

private func setupLocationManager(){

        locationManager.delegate = self
        locationManager.requestAlwaysAuthorization()
        locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
        locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters
        locationManager.allowsBackgroundLocationUpdates = true
        locationManager.activityType = .otherNavigation
    }

func startSignificantChangeLocationUpdates() {

        guard CLLocationManager.significantLocationChangeMonitoringAvailable() else {
            logger.error("significantLocationChangeMonitoringAvailable returned false")
            return
        }

        setupLocationManager()
        locationManager.startMonitoringSignificantLocationChanges()
    }

 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

        // only save data above magical 5m/s =&gt; 18km/h
        var  filteredLocations = locations.filter{$0.speed &gt; 5}

        //only save the fastest item if multiple data is delived
        filteredLocations = filteredLocations.sorted { (l1, l2) -&gt; Bool in
            l1.speed &gt; l2.speed
        }
        if let fastestLocation = filteredLocations.first{
            if (filteredLocations.count &gt; 0){
                //save to DB
                locationModel.addLocations(clLocations: [fastestLocation])
            }
        }
    }
</code></pre>

<p>My problem is that this is not very accurate. Even if I travel more than 10km in 10min by train I just get 2 or 3 datapoints saying that I traveled just 2 minutes.</p>

<p>How can I improve this? <code>kCLLocationAccuracyNearestTenMeters</code> is using a lot of energy. If I compare with Moves then the data is very accurate. But I don't want to integrate their SDK as I try to protect my users privacy.</p>