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

[Bug]: Distance not registered on Google Pixel 6a – Android 14, using Geolocator.getPositionStream #1498

Open
3 of 8 tasks
RabbitQuestBV opened this issue May 2, 2024 · 0 comments

Comments

@RabbitQuestBV
Copy link

RabbitQuestBV commented May 2, 2024

Please check the following before submitting a new issue.

Please select affected platform(s)

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

Steps to reproduce

  1. Start GPS scream using Geolocator.getPositionStream
  2. Start cycling / walking etc..
  3. Distance is not registered

It seems to happen only on certain Android devices.

Expected results

Distance is registered along the way.

Actual results

No distance registered.

Code sample

Code sample
void startPositionStream({
    required void Function(Position) onPositionChanged,
    required Function onError,
  }) async {
    // Cancel stream, if there is any
    await cancelPositionStream();

    // Start listening to the position stream
    _positionSubscription = Geolocator.getPositionStream(
      locationSettings: _initializeLocationSettings(),
    ).listen(
      onPositionChanged,
      onError: onError,
    );
  }

  void _onPositionChanged(Position position) {
    gpsPositions.add(position);

    gpsPositions = _gpsFilterService.filterOutAnomalyPoints(
        positions: gpsPositions, activityType: _challengeActivityType);

    // Calculate distance
    double totalDistance = _gpsAPI.calculateDistance(
      positions: gpsPositions,
    );

    // Add to sink
    final GpsModel gpsModel = _gpsModel.cloneSettingsAndMeters(
      meters: totalDistance,
    );

    gpsStreamController.sink.add(gpsModel);
  }

  double calculateDistance({
    required List<Position> positions,
  }) {
    double totalDistance = 0;
    if (positions.length < 2) {
      return totalDistance;
    }

    for (int i = 1; i < positions.length; i++) {
      Position newPosition = positions[i];
      Position oldPosition = positions[i - 1];

      totalDistance += _geolocatorPlatform.distanceBetween(
        oldPosition.latitude,
        oldPosition.longitude,
        newPosition.latitude,
        newPosition.longitude,
      );
    }
    return totalDistance;
  }

Screenshots or video

Screenshots or video demonstration

[Upload media here]

Version

11.0.0 (geolocator_android = 4.4.1)

Flutter Doctor output

Doctor output ``` [!] Flutter (Channel unknown, 3.10.0, on Microsoft Windows [Version 10.0.22631.3447], locale en-NL) ! Flutter version 3.10.0 on channel unknown at C:\flutter_windows_2.2.3-stable\flutter Currently on an unknown channel. Run `flutter channel` to switch to an official channel. If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install. ! Unknown upstream repository. Reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install. • Framework revision 84a1e904f4 (12 months ago), 2023-05-09 07:41:44 -0700 • Engine revision d44b5a94c9 • Dart version 3.0.0 • DevTools version 2.23.1 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at C:\Users\bart_\AppData\Local\Android\sdk
• Platform android-34, build-tools 31.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
• All Android licenses accepted.

[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop for Windows
X Visual Studio not installed; this is necessary for Windows development.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2020.3)
• Android Studio at C:\Program Files\Android\Android Studio1
• 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 11.0.10+0-b96-7249189)

[√] Android Studio
• Android Studio at C:\Program Files\Android\Android Studio
• 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
• android-studio-dir = C:\Program Files\Android\Android Studio
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[√] VS Code (version 1.88.1)
• VS Code at C:\Users\bart_\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.88.0

[√] Connected device (3 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22631.3447]
• Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.118
• Edge (web) • edge • web-javascript • Microsoft Edge 124.0.2478.67

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

</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant