maplibre / maplibre-navigation-android

Maplibre Navigation SDK for Android
MIT License
86 stars 44 forks source link

Wrong off route state for route snapping #68

Closed Fabi755 closed 6 months ago

Fabi755 commented 1 year ago

While using off-route detection combined with route snapping, the off route position is always snapped.

I already looked inside the code and found the problem. Before the snapped route is calculated, the code is checking for off-route state. If location is off-route the raw location is returned. But the off route function is only return off-route state once, until we will reach again the minimumDistanceBeforeRerouting() from the latest re-route point. But we don't use a re-route logic, and have only one available route.

On OffRouteDetector.java#L132 you see, the off-route is only fired when we above the threshold again. When this check is removed (return true) the off-route event is fired on every location update. That is good for our route snapping, but will also fire our custom off-route callback in our activity/view.

The the location puck should be showed on the red marked position.


Android API: 12 (API 31) Maplibre Navigation SDK version: 2.0.0

Steps to trigger behavior

  1. Enable route snapping & off-routing. Do not support a re-route logic
  2. Start navigation and leave route
  3. Your position will hanging on the last route position. Sometimes it will jump to your current location.

Expected behavior

Route progress will return my raw location all the time.

Actual behavior

Route progress will return snapped location most the time. And if threshold checked, the raw position once. Your position will hanging on the last route position. Sometimes it will jump to your current location.

Fabi755 commented 1 year ago

I'm currently searching for a solution. Maybe we need a re-route controller option like the new Mapbox library. Or I have already thinking about to save the off-route state in the NavigationHelper. But we don't get a back-on-route callback yet.

I will continue to find a solution but maybe one of you have a good idea to solve this issue :blush:

boldtrn commented 1 year ago

This is an issue related to the snapping logic. I am not sure if this is actually a bug, since the default behaviour for most navigation apps would be to recalculate the route. You can change the snapping behaviour though. The logic might depend quite a bit on the application itself. What is your use case?

Fabi755 commented 1 year ago

You can change the snapping behaviour though.

Good point, I can use a customized engine for off-route engine or snap engine.

What is your use case?

Having a fixed routes. For example a bus line. For legal reasons we can not calculate a new route. So we show only the fixed route with a off-route hint, and even the current position.

I am not sure if this is actually a bug

I don't have a solution yet. But I think this is not work as expected. What is happening when the reroute request takes long time, then the own position is showing also on the wrong location. Or I'am wrong with this theory?

And if we ask our off-route logic isOffRoute it should be always returns true if I'm not on the route, and not only every 50 meters. I think we need to separate the two use cases of off-route and re-route. In my mind these are two different things.

Fabi755 commented 6 months ago

I'm using my own customized engine for now. If anyone other has problems with the current default implementation let us know. Then we have a new look on it again.