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

[Question]: Geolocator's Location Stream does not seems to be working sometimes. #1391

Open
3 of 8 tasks
HeronKyaw opened this issue Dec 4, 2023 · 5 comments
Open
3 of 8 tasks
Labels
P2 Important issues not at the top of the work list. platform: android Issue is related to the Android platform. type: bug Something isn't working

Comments

@HeronKyaw
Copy link

HeronKyaw commented Dec 4, 2023

Please check the following before submitting a new issue.

Please select for which platform(s) you need help

  • Android
  • iOS
  • Linux
  • macOS
  • Web
  • Windows

Your question

When I get into the map page without enabling the location service. Everything works as expected. However, when I turn on location again, the location stream does not do anything inside of it (such as .listen and .handleError methods). All the logic and prints inside those mentioned method does not work. I didn't set location settings for specific platforms, so Android should be working with FusedLocationProvider, right?

Anyway, I tried using AndroidSettings with forceLocationManager: true, the stream is working as expected but I don't wanna use legacy location manager for this.

Here's my code

LocationSettings locationSettings = const LocationSettings(
  accuracy: LocationAccuracy.high,
  distanceFilter: 100,
);

void positionListening() {
  if (_positionStreamSubscription == null) {
    final Stream<Position> positionStream = geolocatorPlatform.getPositionStream(
        locationSettings: locationSettings);
    _positionStreamSubscription = positionStream.handleError((error) async {
      if (kDebugMode) {
        print('position stream error $error');
      }
      _positionStreamSubscription?.cancel();
      _positionStreamSubscription = null;
    }).listen((position) {
      if (kDebugMode) {
        print('current position: ${position.latitude} ${position.longitude}');
      }
      updateLocation(position.latitude, position.longitude);
      if (isGoogleMap == 0) {
        moveToRegion(position.latitude, position.longitude);
      }
    });
  } else {
    updateLocation(latitude, longitude);
  }
}
      

Version

^9.0.2

@TimHoogstrate
Copy link
Contributor

Dear @HeronKyaw,

Did you request the correct permissions? And can you explain a bit how you are testing this? Are you testing inside or outside, with a real device or an emulator. And can you paste the output of flutter doctor -v and your manifest file into this post?

Kind regards,

@TimHoogstrate TimHoogstrate added the status: needs more info We need more information before we can continue work on this issue. label Dec 5, 2023
@TimHoogstrate TimHoogstrate self-assigned this Dec 5, 2023
@HeronKyaw
Copy link
Author

HeronKyaw commented Dec 8, 2023

@TimHoogstrate, yup, I did request correct permission, and I'm testing both inside and outside with real device.

Here's the permission inside AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

Flutter Doctor:

[10:37:24] [~] ❱❱❱ flutter doctor -v
[✓] Flutter (Channel stable, 3.10.6, on macOS 14.1.2 23B92 darwin-arm64, locale
    en-MM)
    • Flutter version 3.10.6 on channel stable at /Users/gwt/Documents/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f468f3366c (5 months ago), 2023-07-12 15:19:05 -0700
    • Engine revision cdbeda788a
    • Dart version 3.0.6
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/gwt/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /usr/bin/java
    • Java version OpenJDK Runtime Environment Homebrew (build 17.0.7+0)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.13.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] VS Code (version 1.84.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.76.0

[✓] Connected device (3 available)
    • H3R0n (mobile)  • 166b4ec7dfd99876b662a7185371e4a525309a5e • ios
      • iOS 16.7.2 20H115
    • macOS (desktop) • macos                                    • darwin-arm64
      • macOS 14.1.2 23B92 darwin-arm64
    • Chrome (web)    • chrome                                   •
      web-javascript • Google Chrome 119.0.6045.199

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 categories.

Anyway, I have found a walkaway for this. I have to call something related to getting location such as getCurrentLocation() first before calling the stream. This way works but I think the stream should be working alone, right?

Test case:

  1. Go to map page which calls the stream without opening GPS.
  2. Then once inside of it, try opening the GPS.
  3. Here we don't get any response from the stream.

NOTE: With debug, you'll not face the issue. Try logging this out.

@github-actions github-actions bot removed the status: needs more info We need more information before we can continue work on this issue. label Dec 8, 2023
@mvanbeusekom mvanbeusekom added type: bug Something isn't working platform: android Issue is related to the Android platform. P2 Important issues not at the top of the work list. labels Jan 15, 2024
@mvanbeusekom
Copy link
Member

Thank you for providing the additional information. I have labelled this issue as a bug and added it to our backlog.

@AEZakmee
Copy link

Any updates on this?

@HeronKyaw
Copy link
Author

Any updates for this bug, @mvanbeusekom?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Important issues not at the top of the work list. platform: android Issue is related to the Android platform. type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants