Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

startMonitoringSignificantLocationChanges triggering when stationary

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.

like image 365
Harry J Avatar asked May 25 '26 21:05

Harry J


1 Answers

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)

like image 155
Nitin Alabur Avatar answered May 27 '26 16:05

Nitin Alabur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!