Baseflow / flutter-geolocator

Android and iOS Geolocation plugin for Flutter
https://baseflow.com/
MIT License
1.22k stars 627 forks source link

No further position received from stream #1152

Open i-dentify opened 1 year ago

i-dentify commented 1 year ago

🐛 Bug Report

With location permissions being set to "Accuracy: reduced" I only receive a position when starting the stream - but no further position.

Expected behavior

At least with lowest accuracy submitted via settings there should be a constant position stream.

Reproduction steps

Code, that starts the stream.

_positionStream = Geolocator.getPositionStream(
        locationSettings: _getLocationSettings()
    );
    _positionSubscription = _positionStream!.listen((Position? position) {
      if (position != null && state.status.isActive) {
        add(PositionTracked(
            delivery: delivery,
            position: position
        ));
      }
    }, onError: (error) async {
      try {
        if (state.status.isActive) {
          LocationPermission permissions = await _checkPermissions(
              openAppSettings: true
          );

          if (permissions == LocationPermission.always ||
              permissions == LocationPermission.whileInUse) {
            add(TrackingStopped());
            add(TrackingStarted());
          }
        } else {
          throw error;
        }
      }
      catch (_) {
        rethrow;
      }
    });

  LocationSettings _getLocationSettings() {
    if (Platform.isAndroid) {
      return AndroidSettings(
          accuracy: LocationAccuracy.best
      );
    } else if (Platform.isIOS) {
      return AppleSettings(
        accuracy: LocationAccuracy.best,
        pauseLocationUpdatesAutomatically: true,
        showBackgroundLocationIndicator: false,
      );
    } else {
      return const LocationSettings(
        accuracy: LocationAccuracy.high,
        distanceFilter: 100,
      );
    }
  }

I also tried setting the accuracy to a lower mode step by step. But even with lowest there is no further action on the stream. onError did not get hit. I also added a onDone for testing purpose. But that did not get hit either. The only received position was received within onData - so there was no extra call on something else.

Configuration

Version: 1.x

Platform:

JulianBissekkou commented 1 year ago

Which version of the plugin are you using?

i-dentify commented 1 year ago

geolocator: ^9.0.2

simplenotezy commented 1 year ago

On android, this will not work:

    final position = await Geolocator.getCurrentPosition(
      desiredAccuracy: LocationAccuracy.lowest,
      timeLimit: Duration(seconds: 20),
    );

This is our current workaround:

    final position = await Geolocator.getCurrentPosition(
      // On android .lowest does not work for some reason. Use low instead, or it will load forever.
      desiredAccuracy: Platform.isAndroid ? LocationAccuracy.low : LocationAccuracy.lowest,
      timeLimit: Duration(seconds: 20),
    );
TimHoogstrate commented 12 months ago

Dear @i-dentify,Can you please post the output of flutter doctor -v? Therefore, I can reproduce this issue. And can you also add some detailed information on how you are testing this (e.g. simulator, real-device, indoor/outdoor, permissions granted)?

i-dentify commented 11 months ago

Dear @i-dentify,Can you please post the output of flutter doctor -v? Therefore, I can reproduce this issue. And can you also add some detailed information on how you are testing this (e.g. simulator, real-device, indoor/outdoor, permissions granted)?

I am testing in iOS Simulator with "City run" as selected option. Permissions are set as "While in use" with precise location accuracy being disabled.

flutter doctor -v
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.4.1 22F770820d darwin-x64, locale de-DE)
    • Flutter version 3.10.6 on channel stable at /usr/local/Caskroom/flutter/3.0.3/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f468f3366c (vor 13 Tagen), 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 33.0.2)
    • Android SDK at /Users/mario/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: /Users/mario/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.10121639/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

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

[✓] Android Studio (version 2022.2)
    • Android Studio at /Users/mario/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.10121639/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
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.1.4)
    • IntelliJ at /Users/mario/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    • 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

[✓] IntelliJ IDEA Ultimate Edition (version 2023.1.4)
    • IntelliJ at /Users/mario/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/231.9225.16/IntelliJ IDEA.app
    • 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

[✓] VS Code (version 1.80.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (4 available)
    • TC26 (mobile)              • 20226523022720                       • android-arm64  • Android 10 (API 29)
    • iPhone 14 Pro Max (mobile) • 49DCCDA8-EB9E-4397-8DC4-A2FCE80D1FAA • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)            • macos                                • darwin-x64     • macOS 13.4.1 22F770820d darwin-x64
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 114.0.5735.248

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

• No issues found!