mapbox-navigation-ios icon indicating copy to clipboard operation
mapbox-navigation-ios copied to clipboard

Puck keeps simulating on preview map after ending navigation

Open ShanMa1991 opened this issue 4 years ago • 20 comments

Mapbox Navigation SDK version

2.0.0

Steps to reproduce

  1. choose Example, choose a customized location, start navigation under simulation mode
  2. cancel navigation

Expected behavior

The user location indicator should stop because there's no location update

Actual behavior

There're continuous location update under the passive location provider, which triggers the user location indicator moving in the NavigationMapView as following:

passive

Is this a one-time issue or a repeatable issue?

repeatable

ShanMa1991 avatar Oct 19 '21 22:10 ShanMa1991

Another thing that I've noticed is that on the latest version of Navigation SDK, which is based on v79.0 or higher, we'll start simulation after a couple of seconds of being stale. This is unexpected, since we do not have any location updates.

MaximAlien avatar Nov 12 '21 17:11 MaximAlien

In fact we noticed this issue since we adopted Nav Native 78.0.0 as in the slack .

ShanMa1991 avatar Nov 15 '21 18:11 ShanMa1991

I've checked that it's nothing to do with the simulation mode. After the navigation service ends, we create a new NavigationMapView, and set PassiveLocationProvider to its mapView to override. But we still observe the location update sending from its locationManager, which is NavigationLocationManager that conforms to the CLLocationManager. Which means that even we set to fixed location to the iphone, there's still the location update from the background that simulates the navigation route. Even we manually set the allowsBackgroundLocationUpdates of the PassiveLocationManager.systemLocationManager to false, it still sending the location update.

ShanMa1991 avatar Nov 15 '21 21:11 ShanMa1991

And the cause seems to be that the navigator as the NavigatorObserver keeps observing location update even after the navigation service ends and the user is still in location in a PassiveLocationManager status. But the navigator still sending the simulated location update status to the NotificationCenter as in the following:

https://github.com/mapbox/mapbox-navigation-ios/blob/03523ae1a59e8949bf20fa09b2e6ee25ef5a05d5/Sources/MapboxCoreNavigation/CoreNavigationNavigator.swift#L249-L260

ShanMa1991 avatar Nov 15 '21 21:11 ShanMa1991

Hi @etl , could you take a look at this issue? We've observed the issues related with our navigator as following:

  1. when user is still, the NavigatorObserver keeps receiving the new navigation status as above .
  2. when the navigation service ends, the NavigatorObserver receiving the simulated location update status from the last navigation session.

ShanMa1991 avatar Nov 15 '21 22:11 ShanMa1991

Right now in our example, when we cancel or end the navigation session, we nil out the NavigationViewController and stop the navigation service.

ShanMa1991 avatar Nov 15 '21 22:11 ShanMa1991

@ShanMa1991 Now, the navigator is sending statuses even when there are no UpdateLocations. This is done in order to run the simulation in places where GPS does not work. If you will receive thisNavigationStatus, then NavigationStatusOrigin will be equal to NavigationStatusOrigin::Unconditional. If you don't need such statuses, you can unsubscribe from the observer, or use the pause() resume() methods

keygang avatar Nov 19 '21 10:11 keygang

@mapbox/navigation-ios
I think we should unsubscribe from the observer when the user location is still. The simulated status sending from the background causes the rerouting event and a seconds-delay at the start of active navigation in our Example App. Several crashes are observed related with the unsynced routeProgress which triggers the precondition failure, when we start and cancel navigation several times.

ShanMa1991 avatar Nov 19 '21 22:11 ShanMa1991

Please consider pause/resume, that Stas mentioned, this was design specifically for similar cases.

etl avatar Nov 20 '21 05:11 etl

A note: Pause/resume is controlled for billing purposes as well. Simply calling pause/resume from another place will likely to produce undefined behavior.

S2Ler avatar Nov 22 '21 08:11 S2Ler

The simulated status sending from the background causes the rerouting event and a seconds-delay at the start of active navigation in our Example App.

@ShanMa1991 Can you please clarify what is meant by "from the background" in this case?

S2Ler avatar Nov 22 '21 08:11 S2Ler

@S2Ler Right now we nil out the NavigationMapView for route preview after the active navigation session starts in our Example, but because the navigator stills sending simulated navigation status to the PassiveLocationManager even user is still, we could see the rerouting triggered. And I'm not quiet sure whether it's related with the delay of the start of the active navigation.

For the pause/resume, it would be one way to provide a fix to avoid the simulated location updates while user is still. But how could we stop dealing with the simulated (wrong) location status update in active/passive navigation?

ShanMa1991 avatar Nov 22 '21 20:11 ShanMa1991

For the pause/resume, it would be one way to provide a fix to avoid the simulated location updates while user is still. But how could we stop dealing with the simulated (wrong) location status update in active/passive navigation?

I don't think we should just filter out NavNative updates because we think that they are "incorrect". Maybe we shall use Navigator.resetRideSession after simulation.

navigator stills sending simulated navigation status to the PassiveLocationManager even user is still, we could see the rerouting triggered. And I'm not quiet sure whether it's related with the delay of the start of the active navigation.

I'm confused here. How sending status updates to PassiveLocationManager can trigger reroute?

And I'm not quiet sure whether it's related with the delay of the start of the active navigation.

Can you please provide more info. I don't quite understand this whole problem yet.

S2Ler avatar Nov 30 '21 06:11 S2Ler

Several crashes are observed related with the unsynced routeProgress which triggers the precondition failure, when we start and cancel navigation several times.

I still not able to reproduce this crash. @ShanMa1991 what commit hash do you use for the tests? Can you make a video where this crash is reproduced in Xcode?

S2Ler avatar Nov 30 '21 06:11 S2Ler

@S2Ler According to the NavNative side, that NavigationStatusOrigin::Unconditional says the status is simulated. If in this case, during the free drive or active navigation, should our navigator stop sending out the simulated status? For example, from the UI perspective, when the user is still and active navigation session ends, the map puck should be still. But right now the map puck shows the user is moving, and there's constant location update about the user.

ShanMa1991 avatar Dec 06 '21 19:12 ShanMa1991

But right now the map puck shows the user is moving, and there's constant location update about the user.

@ShanMa1991 Does this happens only after simulated active drive?

S2Ler avatar Dec 07 '21 06:12 S2Ler

@S2Ler Not sure, because Navigator is expected to send out the simulated status when user is still. And when we cancel the navigation and shut down the app and then open again, it still happens.

ShanMa1991 avatar Dec 07 '21 18:12 ShanMa1991

user is still

By user is still, do you mean that we don't provide locations to Native Navigator or that we provide the same location every second?

S2Ler avatar Dec 08 '21 14:12 S2Ler

user is still

By user is still, do you mean that we don't provide locations to Native Navigator or that we provide the same location every second?

I think @ShanMa1991 was referring to the user being at rest, not moving anywhere. It would surprise the user to see the puck keep moving if they aren’t moving. But Core Location normally continues to produce location updates at a steady rate regardless of the user’s inactivity. Moreover, if the application and SDK manages to completely shut off any location and heading updates going to the navigator, the navigator synthesizes its own simulated location updates to compensate. (SimulatedLocationManager does something similar during turn-by-turn navigation.)

1ec5 avatar Mar 18 '22 00:03 1ec5

@mskurydin , could you please take a look and suggest proper way to handle this?

truburt avatar Apr 11 '22 12:04 truburt