From 961183106fb8fdff73d478f382ccfd66b1989209 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Thu, 2 Mar 2017 09:15:02 -0500 Subject: [PATCH 1/2] [android] - activate/deactivate the locationSource when toggling the MyLocationView state. --- .../com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java index 2c3685b8624..60b1144d68d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java @@ -423,22 +423,18 @@ public void onRestoreInstanceState(Parcelable state) { private void toggleGps(boolean enableGps) { LocationEngine locationEngine = LocationSource.getLocationEngine(getContext()); if (enableGps) { - // Set an initial location if one available - Location lastLocation = locationEngine.getLastLocation(); - - if (lastLocation != null) { - setLocation(lastLocation); - } if (userLocationListener == null) { userLocationListener = new GpsLocationListener(this); } locationEngine.addLocationEngineListener(userLocationListener); + locationEngine.activate(); } else { // Disable location and user dot location = null; locationEngine.removeLocationEngineListener(userLocationListener); + locationEngine.deactivate(); } locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY); From 7c1fe5b495000f991cbc8c4fa0ef71e648f5ae64 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Thu, 2 Mar 2017 09:15:39 -0500 Subject: [PATCH 2/2] correct accuracy width --- .../mapboxsdk/maps/widgets/MyLocationView.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java index 60b1144d68d..94d4ca2db2e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java @@ -257,9 +257,7 @@ protected void onDraw(Canvas canvas) { final PointF pointF = screenLocation; float metersPerPixel = (float) projection.getMetersPerPixelAtLatitude(location.getLatitude()); - float accuracyPixels = (Float) accuracyAnimator.getAnimatedValue() / metersPerPixel / 2; - float maxRadius = getWidth() / 2; - accuracyPixels = accuracyPixels <= maxRadius ? accuracyPixels : maxRadius; + float accuracyPixels = (Float) accuracyAnimator.getAnimatedValue() / metersPerPixel; // reset matrix.reset(); @@ -423,6 +421,12 @@ public void onRestoreInstanceState(Parcelable state) { private void toggleGps(boolean enableGps) { LocationEngine locationEngine = LocationSource.getLocationEngine(getContext()); if (enableGps) { + // Set an initial location if one available + Location lastLocation = locationEngine.getLastLocation(); + + if (lastLocation != null) { + setLocation(lastLocation); + } if (userLocationListener == null) { userLocationListener = new GpsLocationListener(this); @@ -726,7 +730,7 @@ void updateAccuracy(@NonNull Location location) { accuracyAnimator.end(); } - accuracyAnimator = ValueAnimator.ofFloat(accuracy * 10, location.getAccuracy() * 10); + accuracyAnimator = ValueAnimator.ofFloat(accuracy, location.getAccuracy()); accuracyAnimator.setDuration(750); accuracyAnimator.start(); accuracy = location.getAccuracy();