Skip to content

Conversation

@orkun1675
Copy link

This PR allows updating the location stream after one is started. It adds a new API endpoint:

  /// Updates the parameters of the active position stream.
  ///
  /// Throws a [NotSubscribedException] when there is no active position stream
  /// to update.
  static Future<void> updatePositionStream({
    required LocationSettings locationSettings,
  }) =>
      GeolocatorPlatform.instance.updatePositionStream(
        locationSettings: locationSettings,
      );

This endpoint allows plugin users to change settings, such as distanceFilter or intervalDuration, without having to stop & start the stream. This is critical if the update is hapenning while the app is in the background since Android does not allow starting a location stream unless the app is in focus.

Fixes #1569. Improved version of #1406.

If there is interest in merging this PR I will clean it up and send for review.


Pre-launch Checklist

  • I made sure the project builds.
  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is does not need version changes.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I rebased onto main.
  • I added new tests to check the change I am making, or this PR does not need tests.
  • I made sure all existing and new tests are passing.
  • I ran dart format . and committed any changes.
  • I ran flutter analyze and fixed any errors.

@orkun1675
Copy link
Author

@TimHoogstrate PLMK if there is interest in merging this PR and I can clean it up.

@TimHoogstrate
Copy link
Contributor

Dear @orkun1675,

Thanks for your PR. We are looking forward to review this. Looks like an interesting addition. I'll do a quick review, try to do a little test and you can clean it up if possible.

Kind regard,

}

@Override
public void updateLocationOptions(LocationOptions options) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a @nonnull or @nullable annotation here.

@Override
public void updateLocationOptions(LocationOptions options) {
this.locationOptions = options;
if (running) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a good idea to notice the developer that the location updates could not be made. Due to .... Or skip keeping track if it is running at all and let the developer manage this. It will prevent errors.

locationClient.startPositionUpdates(activity, positionChangedCallback, errorCallback);
}

public boolean updateLocationOptions(LocationOptions options) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nullable LocationOptions options

private static final String TAG = "GeolocationManager";

private static GeolocationManager geolocationManagerInstance = null;
private static GeolocationManager geolocationManagerInstance = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nullable annotation

CLLocationManager *locationManager = [self getLocationManager];
locationManager.desiredAccuracy = desiredAccuracy;
locationManager.distanceFilter = distanceFilter;
if (@available(iOS 6.0, macOS 10.15, *)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need that @available(iOS 6.0 ?

}

#if TARGET_OS_IOS
if (@available(iOS 9.0, macOS 11.0, *)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, do we need the @available(iOS 9.0, macOS 11.0, *)

@TimHoogstrate
Copy link
Contributor

I've tested this on iOS and Android (Pixel 7) en it seems to work as expected.

@TimHoogstrate TimHoogstrate self-assigned this Mar 31, 2025
@TimHoogstrate
Copy link
Contributor

The idea is to split up the PR in desperate PR's. Separate packages, platform interface and app facing package. If you need any help from us let us know.

Kind regards,

@orkun1675
Copy link
Author

Thank you for the review. I'll address the native plugin comments after #1760 lands.

@orkun1675 orkun1675 changed the title Allow updating location stream settings [WIP] Allow updating location stream settings Nov 22, 2025
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

Successfully merging this pull request may close these issues.

[Question]: Updating accuracy/distanceFilter while the Position stream is running

2 participants