getPositionStream static method

Stream<Position> getPositionStream({
  1. LocationAccuracy desiredAccuracy = LocationAccuracy.best,
  2. int distanceFilter = 0,
  3. bool forceAndroidLocationManager = false,
  4. Duration? intervalDuration,
  5. Duration? timeLimit,
})

Fires whenever the location changes inside the bounds of the desiredAccuracy.

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 precision of the location updates by supplying the desiredAccuracy parameter (defaults to "best"). The distanceFilter parameter controls the minimum distance the device needs to move before the update is emitted (default value is 0 indicator no filter is used). On Android you can force the use of the Android LocationManager instead of the FusedLocationProvider by setting the forceAndroidLocationManager parameter to true. Using the intervalDuration you can control the amount of time that needs to pass before the next position update is send. The timeLimit parameter allows you to specify a timeout interval (by default no time limit is configured).

Throws a TimeoutException when no location is received within the supplied timeLimit duration. Throws a PermissionDeniedException when trying to request the device's location when the user denied access. Throws a LocationServiceDisabledException when the user allowed access, but the location services of the device are disabled.

Implementation

static Stream<Position> getPositionStream({
  LocationAccuracy desiredAccuracy = LocationAccuracy.best,
  int distanceFilter = 0,
  bool forceAndroidLocationManager = false,
  Duration? intervalDuration,
  Duration? timeLimit,
}) =>
    GeolocatorPlatform.instance.getPositionStream(
      desiredAccuracy: desiredAccuracy,
      distanceFilter: distanceFilter,
      forceAndroidLocationManager: forceAndroidLocationManager,
      timeInterval: intervalDuration?.inMilliseconds ?? 0,
      timeLimit: timeLimit,
    );