nww04
nww04

Reputation: 1857

How to turn off tracking in Mapbox when not in use?

So I have a ViewPager with 4 fragments. 3rd fragment is MapBox. Now when the 3rd page was opened, it will call onMapReady, this is the perfect time to configure tracking just like the one on samples.

        mMapboxMap = mapBoxMap;
    mMapboxMap.setMinZoomPreference(Constants.MIN_ZOOM);
    mMapboxMap.setMaxZoomPreference(Constants.MAX_ZOOM);
    mMapboxMap.getMyLocationViewSettings().setPadding(0, 0, 0, 0);
    mMapboxMap.getMyLocationViewSettings().setAccuracyTintColor(ContextCompat.getColor(getContext(), R.color.color_location_accuracy_tint));
    mMapboxMap.getMyLocationViewSettings().setForegroundTintColor(ContextCompat.getColor(getContext(), R.color.color_location_tint));
    mMapboxMap.getTrackingSettings().setDismissAllTrackingOnGesture(true);
    mMapboxMap.setMyLocationEnabled(true);
    mMapboxMap.setOnCameraChangeListener((CameraPosition p) -> onCameraChange(p));
    mMapboxMap.setOnScrollListener(() -> onMapScroll());

    mPermissionManager = new PermissionsManager(this);
    mLocationEngine = AndroidLocationEngine.getLocationEngine(getActivity());
    mLocationEngine.activate();

    enableTracking(true);

When I switch back to page 1, 3rd page will be discarded as per ViewPager behavior. The problem is that, it still tracking for GPS as I can see the notif bar has the GPS indicator still on.

I terminate it like this:

    mLocationEngine.removeLocationUpdates();
    mLocationEngine.deactivate();
    mLocationEngine.removeLocationEngineListener(mLocationEngineListener);
    enableTracking(false);

Here is my enableTracking method:

public void enableTracking(boolean enable)
{
    mMapboxMap.getTrackingSettings().setMyLocationTrackingMode(enable? MyLocationTracking.TRACKING_FOLLOW : MyLocationTracking.TRACKING_NONE);
}

Any ideas why this happening?

Upvotes: 0

Views: 372

Answers (1)

zugaldia
zugaldia

Reputation: 702

Looks like you're hitting this issue present in the underlying location library that Mapbox uses. This should be fixed in the next release 5.1.0.

Upvotes: 2

Related Questions