From 95ef6c04ce3306dfe0c4a1101549d7feba0f2e99 Mon Sep 17 00:00:00 2001 From: danesfeder Date: Thu, 24 May 2018 15:18:43 -0400 Subject: [PATCH] Initialize LocationEngine for all constructors --- .../plugins/locationlayer/LocationLayerPlugin.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java index e41d6d7a8..95393f277 100644 --- a/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java +++ b/plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java @@ -95,7 +95,6 @@ public LocationLayerPlugin(@NonNull MapView mapView, @NonNull MapboxMap mapboxMa this.mapboxMap = mapboxMap; this.mapView = mapView; options = LocationLayerOptions.createFromAttributes(mapView.getContext(), R.style.mapbox_LocationLayer); - initializeLocationEngine(); initialize(); } @@ -488,6 +487,7 @@ void onLocationLayerStop() { } private void initialize() { + initializeLocationEngine(); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); mapboxMap.addOnMapClickListener(onMapClickListener); @@ -512,11 +512,13 @@ private void initialize() { } private void initializeLocationEngine() { - usingInternalLocationEngine = true; - locationEngine = new LocationEngineProvider(mapView.getContext()).obtainBestLocationEngineAvailable(); - locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY); - locationEngine.setFastestInterval(1000); - locationEngine.activate(); + if (locationEngine == null) { + usingInternalLocationEngine = true; + locationEngine = new LocationEngineProvider(mapView.getContext()).obtainBestLocationEngineAvailable(); + locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY); + locationEngine.setFastestInterval(1000); + locationEngine.activate(); + } } private void enableLocationLayerPlugin() {