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

onUserLocationUpdated not firing (Android, v0.9.0). #444

Closed
thomfra opened this issue Oct 28, 2020 · 13 comments
Closed

onUserLocationUpdated not firing (Android, v0.9.0). #444

thomfra opened this issue Oct 28, 2020 · 13 comments
Labels

Comments

@thomfra
Copy link

thomfra commented Oct 28, 2020

I am not getting any updates on position when my app is starting. However, when I turn off and on the screen again, the callbacks are firing as expected. Anyone else experiencing this?

On iOS on the other hand it works like a charm.

@n00bsys0p
Copy link

We have exactly the same problem. On iOS onUserLocationUpdated fires fine, but on Android it doesn't fire until after the screen is turned off and on again. Totally reliable.

@thomfra Did you ever find a solution to the problem?

@Vivalemuc
Copy link

Vivalemuc commented Feb 16, 2021

Exactly the same here !

Any solutions ?

Or the best is to use another solution to track the user position on Android ? (Pitty)

@Vivalemuc
Copy link

@n00bsys0p I fork the project and modify MapboxMapController like this :

On line 315 i replace the block by :

 if (myLocationEnabled) {
      updateMyLocationEnabled();
}

Obviously the permission need to be granted before this call, so ensure the permission is granted before call the map initialization

@mayouf
Copy link

mayouf commented Feb 17, 2021

@n00bsys0p I fork the project and modify MapboxMapController like this :

On line 315 i replace the block by :

 if (myLocationEnabled) {
      updateMyLocationEnabled();
}

Obviously the permission need to be granted before this call, so ensure the permission is granted before call the map initialization

Can you be more specific ? what file (java, dart), what function ?

I have the same issue. When I change location permission on Android 9, the permission do not propagate. So, we need to restart the app to make it work.

@Vivalemuc
Copy link

The android/MapboxMapController.java file !
On line 315, you need to replace enable....() by updateMyLocationEnabled() !

But you need to granted location permission before the display of the map ;)

@mayouf
Copy link

mayouf commented Feb 17, 2021

@Vivalemuc thx for replying quickly, kind of you...

Correct us if im wrong and for those future dev coming meeting the same bug:

  1. You edited the following file: flutter-mapbox-gl/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java

  2. At the line 315, you have this block:

 if (myLocationEnabled) {
        enableLocationComponent(style);
      }
  1. And you replace this block by the code below
if (myLocationEnabled) {
      updateMyLocationEnabled();  // this line was replaced
}

By doing that, the app crashes !!

@Vivalemuc
Copy link

Look at my fork :

https://github.com/Vivalemuc/flutter-mapbox-gl/blob/master/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java

You can try it ;)
You must change another line of code, but it's not related with this bug, so just clone my fork or try it on your pubspec to see the result ;)

@mayouf
Copy link

mayouf commented Feb 17, 2021

Not working here ! Thx a lot @Vivalemuc for sharing and answering.

I'll dig it and let people know here when I found out.

For sure, it is not related to the plugin flutter-permission-handler .

The isGranted permission is correctly propagated. This is related to mapbox-gl.

@Vivalemuc
Copy link

Last answer :

On your pubspec.yaml put this :

 mapbox_gl:
    git:
      url: https://github.com/Vivalemuc/flutter-mapbox-gl.git
      ref: master

The plugin is working properly for me on fluter dev 1.26...

@mayouf
Copy link

mayouf commented Feb 17, 2021

Hi @tobrun,

Litlle by little, devices are updating to android 10 and even 11.

The permission handling is getting more complicated with more choices: check below HOW IT EVOLVES.

From android 9, we went from simple location permission to:

  • A double level permission (foreground + background).
  • It is related with multiple permission choice possible:

While using the app
Only this time
Deny
Ask every time.

Do you think you can give us a clue on how to handle the permission change while the app is running without crashing ?

image

vberthet pushed a commit to MdnAgency/flutter-maplibre-gl that referenced this issue Aug 27, 2021
@JanIceTea
Copy link

Has this ever been picked up? I'm using the latest version 0.12.0 and still have the same issue. This makes it pretty much un-usable on Android.

vberthet pushed a commit to MdnAgency/flutter-maplibre-gl that referenced this issue Oct 5, 2021
m0nac0 pushed a commit to maplibre/flutter-maplibre-gl that referenced this issue Oct 5, 2021
* Fix onUserLocationUpdated not firing on android (see flutter-mapbox-gl/maps#444)

* FIX SIGABRT when location permission is missing

Co-authored-by: Vincent Berthet <vincent@web-74.com>
@KawindaWAD
Copy link

KawindaWAD commented Nov 9, 2021

in MapboxMap widget, myLocationEnabled parameter should be set as false when creating the screen. you can set it to true after creating the map by using onMapCreated function. then onUserLocationUpdated function works normally.

bool _myLocationEnabled = false;

MapboxMap(
    onMapCreated: onMapCreated,
    onUserLocationUpdated: (userLocation) {
          print("User location updated: ${userLocation.position}");
    },
    myLocationEnabled: _myLocationEnabled,
)

void onMapCreated(MapboxMapController controller) {
    setState(() {
      this.mapController = controller;
      _myLocationEnabled = true;
    });
}

@stale
Copy link

stale bot commented Jan 14, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 14, 2022
@stale stale bot closed this as completed Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants