watchGeolocationPosition method

Stream<GeolocationPosition> watchGeolocationPosition({
  1. bool enableHighAccuracy = true,
  2. Duration timeout = const Duration(seconds: 15),
  3. Duration maximumAge = const Duration(minutes: 5),
})

Implementation

Stream<GeolocationPosition> watchGeolocationPosition({
  bool enableHighAccuracy = true,
  Duration timeout = const Duration(seconds: 15),
  Duration maximumAge = const Duration(minutes: 5),
}) {
  final controller = StreamController<GeolocationPosition>();

  final watchId = watchPosition(
    (GeolocationPosition geoPos) {
      controller.add(geoPos);
    }.toJS,
    (GeolocationPositionError geoPosError) {
      controller.addError(geoPosError);
    }.toJS,
    PositionOptions(
        enableHighAccuracy: enableHighAccuracy,
        timeout: timeout.inMilliseconds,
        maximumAge: maximumAge.inMilliseconds),
  );

  controller.onCancel = () {
    clearWatch(watchId);
  };

  var stream = controller.stream;
  return stream;
}