Skip to content

Animation not working after removing location updates and adding them again #126

Closed

Description

@kkalera

Hi,

I've been trying to use the location layer plugin but I'm having some issues when I remove the location updates and add them again.
When I start the application, the location marker moves smoothly when changing location.
However; when I remove the location updates from the locationEngine (in onPause or onStop functions) and I call "requestLocationUpdates" on the locationEngine, the navigation icon just snaps to the new location.

I have provided a gif below to show you:
(ignore the reverse part, apparently my gif maker also reversed it)
videotogif_2017 10 03_20 22 07 1

Code is copied from the example to be sure I'm not the problem.
I have the following code in my onMapReadyCallback:
locationEngine = new LostLocationEngine(MainActivity.this); locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY); locationEngine.addLocationEngineListener(MainActivity.this); locationEngine.activate(); locationLayerPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine); getLifecycle().addObserver(locationLayerPlugin);

In my "onStart()" and "onResume()" lifecycle methods i'm calling the following function:
public void enableLocation(){ if(ContextCompat.checkSelfPermission(getApplicationContext(),Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){ if (locationEngine != null) { locationEngine.requestLocationUpdates(); locationEngine.addLocationEngineListener(MainActivity.this); } if(locationLayerPlugin != null && locationLayerPlugin.getLocationLayerMode() != LocationLayerMode.NAVIGATION){ locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.NAVIGATION); } }else{ Log.e("trp", "Location permission not granted"); } }

And finally in my "onPause()" ,"onStop()" and "onDestroy()" lifecycle methods, I'm calling the following function;
`public void disableLocation(){

    if (locationEngine != null) {
        locationEngine.removeLocationEngineListener(MainActivity.this);
        locationEngine.removeLocationUpdates();
    }
}`

Activity

  1. added
    location-layer-plugin
    on Oct 4, 2017
  2. kkalera commented on Oct 12, 2017

    @kkalera
    Author

    I found something weird regarding this issue. When my user is on a route, I'm snapping the location update to that route. When the user's location is snapped , I'm using NavigationLayerPlugin.forceLocationUpdate(Location).

    The weird thing is, that when I use that function after snapping the users location to the route, everything works fine. But if I use that function on the location update itself, it's jumpy.

    I have included another gif to showcase this;
    videotogif_2017 10 12_08 50 24

    I was thinking it might have something to do with the location received from OnLocationChanged so I already tried creating a new Location object. The same way I do when I'm using the snapping function, this doesn't solve the issue.

  3. kkalera commented on Oct 12, 2017

    @kkalera
    Author

    I found a work-around. Only updating the location in the 'OnLocationChanged' function when the last update was more than 500ms ago, solves the problem.

    If anybody is interested in the code (beware it's in kotlin. But adapting it to java is pretty easy):
    private var lastLocUpdate:Long = -1 if(lastLocUpdate.equals(-1) || (System.currentTimeMillis() - lastLocUpdate) > 500){ locationLayerPlugin.forceLocationUpdate(location) lastLocUpdate = System.currentTimeMillis() }

  4. added this to the location-layer-0.3.0 milestone on Dec 2, 2017
  5. cammace commented on Dec 22, 2017

    @cammace

    Thanks for posting a workaround. This is a similar issue to #215 and the fix for that issue should also fix this one. Closing and will track the issue in that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    location-layer-plugin

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions