I have an application for a client that requires me to use the startMonitoringSignificantLocationChanges() method however when I am stationary and haven't moved for a period of time, it will still trigger.
My location manager code is as below:
locationManager = CLLocationManager()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.distanceFilter = 1500
locationManager.startUpdatingLocation()
locationManager.delegate = self
locationManager.startMonitoringSignificantLocationChanges()
locationManager.allowsBackgroundLocationUpdates = true
locationManager.pausesLocationUpdatesAutomatically = false
then my didUpdateLocations
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location: CLLocation = locations.last!
print("Location: \(location)")
print("SIGNIFICANT CHANGE")
}
When I am travelling it prints every 1500ish metres as expected however it triggers when not expected and I am lost of a solution or probable problem.
Would activityType help?
Since you are using it to travel, you could probably ignore walking or non automotive movements?
If that is not an option, you could try figuring in didUpdateLocations about the horizontal/vertical accuracy of your CLLocation object. ignore if it isn't within a threshold (this may lead to a few false negatives)
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