Reputation: 1966
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.
Upvotes: 3
Views: 505
Reputation: 5812
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)
Upvotes: 1
Reputation: 113777
You can't rely on startMonitoringSignificantLocationChanges()
to give you consistent results. If you go to an area with low cell tower density the distance you have to move before it gets triggered will change again. It's a low-power location method with low reliability.
That being said, it's unusual for it to trigger when you haven't moved. Maybe your device switched cell towers? Maybe it's a bug. File a report, make a small test project and send it in to Apple with your log files.
I don't know your requirements but one solution is to save (in an instance variable and as a file) the last found location and compare the distance between that and the new location to see if you've actually moved a long way. The other is to use region monitoring.
Upvotes: 1