Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed LocationTracking issue delayed permissions #958

Conversation

felix-ht
Copy link
Collaborator

@felix-ht felix-ht commented Mar 22, 2022

On android if the users starts up the app for the first time it has no permissions to track the user location. Even if the the location tracking mode is later changed the location puck would not show because the locationComponent does not come up.

This PR fixes that by activating the locationComponent on a mode change if it hasn’t already been activated.

@felix-ht felix-ht temporarily deployed to ANDROID_CI_DOWNLOADS_TOKEN March 22, 2022 14:48 Inactive
@felix-ht felix-ht temporarily deployed to ANDROID_CI_DOWNLOADS_TOKEN March 22, 2022 14:48 Inactive
@felix-ht felix-ht added bug Something isn't working android labels Mar 22, 2022
@felix-ht felix-ht force-pushed the fixed-LocationTrackingMode-not-working-with-delayed-permissions branch from 8fdb5e3 to bd28c48 Compare March 22, 2022 14:49
@felix-ht felix-ht temporarily deployed to ANDROID_CI_DOWNLOADS_TOKEN March 22, 2022 14:49 Inactive
@felix-ht felix-ht temporarily deployed to ANDROID_CI_DOWNLOADS_TOKEN March 22, 2022 14:49 Inactive
@felix-ht felix-ht requested a review from Chaoba March 22, 2022 15:00
@felix-ht felix-ht temporarily deployed to ANDROID_CI_DOWNLOADS_TOKEN March 23, 2022 10:01 Inactive
@felix-ht felix-ht temporarily deployed to ANDROID_CI_DOWNLOADS_TOKEN March 23, 2022 10:02 Inactive
@AAverin
Copy link
Contributor

AAverin commented Mar 24, 2022

Does this resolve?

E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): Failed to handle method call
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): com.mapbox.mapboxsdk.style.layers.CannotAddLayerException: Could not find layer: mapbox-location-bearing-layer
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxsdk.maps.NativeMapView.nativeAddLayerAbove(Native Method)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxsdk.maps.NativeMapView.addLayerAbove(NativeMapView.java:874)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxsdk.maps.Style.addLayerAbove(Style.java:215)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxsdk.location.LocationComponentPositionManager.addLayerToMap(LocationComponentPositionManager.java:41)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxsdk.location.SymbolLocationLayerRenderer.addLayers(SymbolLocationLayerRenderer.java:90)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxsdk.location.LocationLayerController.applyStyle(LocationLayerController.java:95)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxsdk.location.LocationComponent.applyStyle(LocationComponent.java:762)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxgl.MapboxMapController.updateLocationLocationComponentLayer(MapboxMapController.java:287)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxgl.MapboxMapController.onMethodCall(MapboxMapController.java:826)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:320)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at android.os.Handler.handleCallback(Handler.java:873)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at android.os.Looper.loop(Looper.java:193)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at android.app.ActivityThread.main(ActivityThread.java:6718)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

@felix-ht felix-ht merged commit 17a701f into master Mar 24, 2022
@felix-ht felix-ht deleted the fixed-LocationTrackingMode-not-working-with-delayed-permissions branch March 24, 2022 13:02
@felix-ht
Copy link
Collaborator Author

Does this resolve?

E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): Failed to handle method call
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): com.mapbox.mapboxsdk.style.layers.CannotAddLayerException: Could not find layer: mapbox-location-bearing-layer
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxsdk.maps.NativeMapView.nativeAddLayerAbove(Native Method)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxsdk.maps.NativeMapView.addLayerAbove(NativeMapView.java:874)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxsdk.maps.Style.addLayerAbove(Style.java:215)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxsdk.location.LocationComponentPositionManager.addLayerToMap(LocationComponentPositionManager.java:41)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxsdk.location.SymbolLocationLayerRenderer.addLayers(SymbolLocationLayerRenderer.java:90)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxsdk.location.LocationLayerController.applyStyle(LocationLayerController.java:95)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxsdk.location.LocationComponent.applyStyle(LocationComponent.java:762)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxgl.MapboxMapController.updateLocationLocationComponentLayer(MapboxMapController.java:287)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.mapbox.mapboxgl.MapboxMapController.onMethodCall(MapboxMapController.java:826)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:320)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at android.os.Handler.handleCallback(Handler.java:873)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at android.os.Looper.loop(Looper.java:193)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at android.app.ActivityThread.main(ActivityThread.java:6718)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
E/MethodChannel#plugins.flutter.io/mapbox_maps_6(14404): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

unlikely - when do you get this error?

@AAverin
Copy link
Contributor

AAverin commented Mar 24, 2022

@felix-ht Seems to happen if I decline location permissions.
it also results in geojson bugs, at least updating geojson source doesn't work correctly after this exception happens

@felix-ht
Copy link
Collaborator Author

@AAverin this is quite strange as the locationComponent should be null if there are no permissions.

@felix-ht
Copy link
Collaborator Author

try this diff @AAverin

diff --git a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java b/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
index 4a352bc..96a9fe4 100644
--- a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
+++ b/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
@@ -281,8 +281,8 @@ final class MapboxMapController
     }
   }
 
-  private void updateLocationLocationComponentLayer() {
-    if (locationComponent != null && style != null) {
+  private void updateLocationComponentLayer() {
+    if (locationComponent != null && style != null && hasLocationPermission()) {
       locationComponent.applyStyle(buildLocationComponentOptions(style));
     }
   }
@@ -822,7 +822,7 @@ final class MapboxMapController
               properties,
               enableInteraction,
               null);
-          updateLocationLocationComponentLayer();
+          updateLocationComponentLayer();
 
           result.success(null);
           break;
@@ -848,7 +848,7 @@ final class MapboxMapController
               properties,
               enableInteraction,
               null);
-          updateLocationLocationComponentLayer();
+          updateLocationComponentLayer();
 
           result.success(null);
           break;
@@ -874,7 +874,7 @@ final class MapboxMapController
               properties,
               enableInteraction,
               null);
-          updateLocationLocationComponentLayer();
+          updateLocationComponentLayer();
 
           result.success(null);
           break;
@@ -900,7 +900,7 @@ final class MapboxMapController
               properties,
               enableInteraction,
               null);
-          updateLocationLocationComponentLayer();
+          updateLocationComponentLayer();
 
           result.success(null);
           break;
@@ -922,7 +922,7 @@ final class MapboxMapController
               belowLayerId,
               properties,
               null);
-          updateLocationLocationComponentLayer();
+          updateLocationComponentLayer();
 
           result.success(null);
           break;
@@ -944,7 +944,7 @@ final class MapboxMapController
               belowLayerId,
               properties,
               null);
-          updateLocationLocationComponentLayer();
+          updateLocationComponentLayer();
 
           result.success(null);
           break;

@AAverin
Copy link
Contributor

AAverin commented Mar 24, 2022

I have now updated to latest master and issue is still there: #968

FreeGrow added a commit to FreeGrow/maps that referenced this pull request Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants