summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukasz.paczos@mapbox.com>2018-12-17 13:17:31 +0100
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2018-12-18 17:29:47 +0100
commitfbe7874db50e343740f3d065a8c06e7ceb07002e (patch)
tree5eb81954adaaef0b0f286ca6e82bafe06e761d40
parentc01c8282fe6e3de1cb65223efc50d36bad4d591f (diff)
downloadqtlocation-mapboxgl-fbe7874db50e343740f3d065a8c06e7ceb07002e.tar.gz
[android] location update fastest interval workaround
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java18
1 files changed, 16 insertions, 2 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
index 07194cdc89..d4083c6634 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
@@ -5,6 +5,7 @@ import android.content.Context;
import android.hardware.SensorManager;
import android.location.Location;
import android.os.Looper;
+import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresPermission;
@@ -162,6 +163,10 @@ public final class LocationComponent {
private final CopyOnWriteArrayList<OnCameraTrackingChangedListener> onCameraTrackingChangedListeners
= new CopyOnWriteArrayList<>();
+ // Workaround for too frequent updates, see https://github.com/mapbox/mapbox-gl-native/issues/13587
+ private long fastestInterval;
+ private long lastUpdateTime;
+
/**
* Internal use.
* <p>
@@ -693,19 +698,21 @@ public final class LocationComponent {
@SuppressLint("MissingPermission")
public void setLocationEngine(@Nullable LocationEngine locationEngine) {
if (this.locationEngine != null) {
- // If internal location engines being used, extra steps need to be taken to deconstruct the
- // instance.
+ // If internal location engines being used, extra steps need to be taken to deconstruct the instance.
this.locationEngine.removeLocationUpdates(currentLocationEngineListener);
this.locationEngine = null;
}
if (locationEngine != null) {
+ fastestInterval = locationEngineRequest.getFastestInterval();
this.locationEngine = locationEngine;
if (isLayerReady && isEnabled) {
setLastLocation();
locationEngine.requestLocationUpdates(
locationEngineRequest, currentLocationEngineListener, Looper.getMainLooper());
}
+ } else {
+ fastestInterval = 0;
}
}
@@ -1112,6 +1119,13 @@ public final class LocationComponent {
} else if (!isLayerReady) {
lastLocation = location;
return;
+ } else {
+ long currentTime = SystemClock.elapsedRealtime();
+ if (currentTime - lastUpdateTime < fastestInterval) {
+ return;
+ } else {
+ lastUpdateTime = currentTime;
+ }
}
showLocationLayerIfHidden();