watchPosition method

Stream<Geoposition> watchPosition (
  1. {bool? enableHighAccuracy,
  2. Duration? timeout,
  3. Duration? maximumAge}
)

Implementation

Stream<Geoposition> watchPosition(
    {bool? enableHighAccuracy, Duration? timeout, Duration? maximumAge}) {
  var options = {};
  if (enableHighAccuracy != null) {
    options['enableHighAccuracy'] = enableHighAccuracy;
  }
  if (timeout != null) {
    options['timeout'] = timeout.inMilliseconds;
  }
  if (maximumAge != null) {
    options['maximumAge'] = maximumAge.inMilliseconds;
  }

  int? watchId;
  StreamController<Geoposition> controller =
      new StreamController<Geoposition>(
          sync: true,
          onCancel: () {
            assert(watchId != null);
            _clearWatch(watchId!);
          });
  controller.onListen = () {
    assert(watchId == null);
    watchId = _watchPosition((position) {
      controller.add(_ensurePosition(position));
    }, (error) {
      controller.addError(error);
    }, options);
  };

  return controller.stream;
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-html/Geolocation/watchPosition.html