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() {