Skip to content

Commit

Permalink
Deactivate location updates when the map is destroyed #236
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Jul 2, 2018
1 parent 226bc13 commit e0c8042
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions src/mapbox.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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 = {};
Expand Down

0 comments on commit e0c8042

Please sign in to comment.