From e0c8042395f60e8d21f587d4f92e59ed43657712 Mon Sep 17 00:00:00 2001 From: EddyVerbruggen Date: Mon, 2 Jul 2018 17:47:36 +0200 Subject: [PATCH] Deactivate location updates when the map is destroyed #236 --- CHANGELOG.md | 2 +- src/mapbox.android.ts | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0344595..0007f93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ - User Tracking Mode [\#144](https://github.com/EddyVerbruggen/nativescript-mapbox/issues/144) - Build error on Android, related to source level 1.8 [\#234](https://github.com/EddyVerbruggen/nativescript-mapbox/issues/234) - Add support for a 'stroke' around a Polygon [\#235](https://github.com/EddyVerbruggen/nativescript-mapbox/issues/235) - +- Deactivate location updates when the map is destroyed [\#236](https://github.com/EddyVerbruggen/nativescript-mapbox/issues/236) ## [4.0.0](https://github.com/EddyVerbruggen/nativescript-mapbox/tree/4.0.0) (2018-05-07) [Full Changelog](https://github.com/EddyVerbruggen/nativescript-mapbox/compare/3.3.0...4.0.0) diff --git a/src/mapbox.android.ts b/src/mapbox.android.ts index 3df5376..7af3ad6 100755 --- a/src/mapbox.android.ts +++ b/src/mapbox.android.ts @@ -65,6 +65,13 @@ export class MapboxView extends MapboxViewBase { return nativeView; } + disposeNativeView(): void { + if (_locationEngine) { + _locationEngine.deactivate(); + _locationEngine = null; + } + } + initMap(): void { if (!this.mapView && this.config.accessToken) { this.mapbox = new Mapbox(); @@ -217,8 +224,6 @@ const _showLocation = (theMapView, mapboxMap) => { _locationEngine = new com.mapbox.android.core.location.LocationEngineProvider(application.android.foregroundActivity || application.android.startActivity).obtainBestLocationEngineAvailable(); _locationEngine.setPriority(com.mapbox.android.core.location.LocationEnginePriority.HIGH_ACCURACY); _locationEngine.setFastestInterval(1000); - - // TODO deactivate when the map is destroyed _locationEngine.activate(); } @@ -577,6 +582,10 @@ export class Mapbox extends MapboxCommon implements MapboxApi { if (viewGroup !== null) { viewGroup.removeView(theMap.mapView); } + if (_locationEngine) { + _locationEngine.deactivate(); + _locationEngine = null; + } theMap.mapView = null; theMap.mapboxMap = null; _mapbox = {};