Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

startMonitoringSignificantLocationChanges not starting instantly

I'm working on a navigation application, everything working in terminated, background and fore ground state. But in one scenario of terminated state startMonitoringSignificantLocationChanges is not handling itself.

The issue is

  • when i start the startMonitoringSignificantLocationChanges and killed the app, then I'm getting location event like after 0.5-1km because of that it draws straight line from my initial position to the first location event I get.But when the location event starts coming then everything work smoothly
  • Same issue occur again when in the middle of travelling I open the application to check my route status and then kill the application, again location events start coming after 0.5-1km and a straight line was drawn.

The code is straight

    significantLocationManager = CLLocationManager()
    significantLocationManager?.allowsBackgroundLocationUpdates = true
    significantLocationManager?.pausesLocationUpdatesAutomatically = false
    significantLocationManager?.requestAlwaysAuthorization()

and call the tracking when user needs by

significantLocationManager?.startMonitoringSignificantLocationChanges()

Rest I have handled the incoming location event in the app delegate to save in db.

So question is how should I handle this scenario in which straight line is drawn ?

like image 977
Parv Bhasker Avatar asked Apr 30 '26 11:04

Parv Bhasker


1 Answers

From Apple documentation:

Apps can expect a notification as soon as the device moves 500 meters or more from its previous notification. It should not expect notifications more frequently than once every five minutes. If the device is able to retrieve data from the network, the location manager is much more likely to deliver notifications in a timely manner.

If you need to receive location updates as soon as possible I'd recommend to use startUpdatingLocation() with desired distanceFilter of CLLocationManager.

like image 78
HereTrix Avatar answered May 04 '26 14:05

HereTrix



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!