getPositionStream static method

Stream<Position> getPositionStream({
  1. LocationSettings? locationSettings,
})

Fires whenever the location changes inside the bounds of the supplied LocationSettings.accuracy.

This event starts all location sensors on the device and will keep them active until you cancel listening to the stream or when the application is killed.

StreamSubscription<Position> positionStream = getPositionStream()
    .listen((Position position) {
      // Handle position changes
    });

// When no longer needed cancel the subscription
positionStream.cancel();

You can control the behavior of the stream by specifying an instance of the LocationSettings class for the locationSettings parameter. Standard settings are:

  • LocationSettings.accuracy: allows controlling the precision of the position updates by supplying (defaults to "best");
  • LocationSettings.distanceFilter: allows controlling the minimum distance the device needs to move before the update is emitted (default value is 0 which indicates no filter is used);
  • LocationSettings.timeLimit: allows for setting a timeout interval. If between fetching locations the timeout interval is exceeded a TimeoutException will be thrown. By default no time limit is configured.

If you want to specify platform specific settings you can use the AndroidSettings and AppleSettings classes.

Throws a TimeoutException when no location is received within the supplied timeLimit duration. Throws a LocationServiceDisabledException when the user allowed access, but the location services of the device are disabled.

Implementation

static Stream<Position> getPositionStream({
  LocationSettings? locationSettings,
}) =>
    GeolocatorPlatform.instance.getPositionStream(
      locationSettings: locationSettings,
    );