Baseflow / Baseflow/flutter-geolocator

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

Open
#1,391 7 comments 0 reactions 0 assignees View on GitHub
P2 platform: android type: bug
Dominant language
Dart
Stars
1.3k
Forks
803
Avg merge
8h 16m
Merged PRs (30d)
1

Description

### Please check the following before submitting a new issue.

- [X] I have searched the [existing issues](https://github.com/baseflow/flutter-geolocator/issues).
- [X] I have carefully [read the documentation](https://github.com/baseflow/flutter-geolocator/blob/main/geolocator/README.md).

### Please select for which platform(s) you need help

- [X] 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

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

void positionListening() {
if (_positionStreamSubscription == null) {
final Stream 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

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Android location-service off/on sequence in version 9.0.2, comparing getPositionStream with AndroidSettings(forceLocationManager: true). Then inspect the stream behavior around the reported listen and handleError callbacks; done means identifying the fused-provider failure or documenting the supported behavior with a regression test if one is feasible.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, dart, flutter
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.