flutter-geolocator
flutter-geolocator copied to clipboard
[Question]: Geolocator.getPositionStream triggers frame refreshes when used with MapLibre_gl
Please check the following before submitting a new issue.
- [x] I have searched the existing issues.
- [x] I have carefully read the documentation.
Please select for which platform(s) you need help
- [x] Android
- [ ] iOS
- [ ] Linux
- [ ] macOS
- [ ] Web
- [ ] Windows
Your question
Using Geolocator.getPositionStream with MapLibre_gl causes frame refreshes on Android, even when the GPS coordinates are not changing. This behavior, observed on Android but not iOS, leads to constant frame generation.
Versions:
- geolocator: 14.0.1
- maplibre_gl: 0.22.0
Sample code to reproduce the issue:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:maplibre_gl/maplibre_gl.dart';
class TestGeolocator extends StatefulWidget {
const TestGeolocator({super.key});
@override
State<TestGeolocator> createState() => _TestGeolocatorState();
}
class _TestGeolocatorState extends State<TestGeolocator> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async {
await _trackCoordinates();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: MapLibreMap(
compassViewPosition: CompassViewPosition.topRight,
styleString: 'https://style_url',
myLocationEnabled: true,
initialCameraPosition: const CameraPosition(
target: LatLng(40.947970551634754, -4.118041773948952),
zoom: 18.5,
),
trackCameraPosition: true,
),
),
);
}
Future<void> _trackCoordinates() async {
var locationSettings = const LocationSettings(accuracy: LocationAccuracy.high, distanceFilter: 5);
Geolocator.getPositionStream(locationSettings: locationSettings).listen((position) async {
print('${position.latitude}, ${position.longitude}');
});
}
}
Any idea on how to prevent this?
Thanks!
Version
14.0.1
Dear @tmorell,
Thanks for your update. Can you add the output of flutter doctor -v to this issue?
Kind regards,
Output from doctor
❯ flutter doctor -v
[✓] Flutter (Channel stable, 3.32.2, on macOS 15.5 24F74 darwin-arm64, locale en-US) [973ms]
• Flutter version 3.32.2 on channel stable at /Users/xxx/fvm/versions/stable
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 8defaa71a7 (7 days ago), 2025-06-04 11:02:51 -0700
• Engine revision 1091508939
• Dart version 3.8.1
• DevTools version 2.45.1
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [2.6s]
• Android SDK at /Users/xxx/Library/Android/sdk
• Platform android-35, build-tools 35.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
This is the JDK bundled with the latest Android Studio installation on this machine.
To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
• Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 16.2) [1,711ms]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16C5032a
• CocoaPods version 1.16.2
[✓] Chrome - develop for the web [9ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2024.3) [9ms]
• 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
• Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
[✓] VS Code (version 1.100.3) [7ms]
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.112.0
[✓] Connected device (2 available) [5.8s]
• macOS (desktop) • macos • darwin-arm64 • macOS 15.5 24F74 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 137.0.7151.69
! Error: Browsing on the local area network for xxxxx’s iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area
network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] Network resources [749ms]
• All expected network resources are available.
• No issues found!