watchPosition method

  1. @DomName('Geolocation.watchPosition')
Stream<Geoposition> watchPosition({bool enableHighAccuracy, Duration timeout, Duration maximumAge })

Source

@DomName('Geolocation.watchPosition')
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;
  // TODO(jacobr): it seems like a bug that we have to specifiy the static
  // type here for controller.stream to have the right type.
  // dartbug.com/26278
  StreamController<Geoposition> controller;
  controller = new StreamController<Geoposition>(
      sync: true,
      onListen: () {
        assert(watchId == null);
        watchId = _watchPosition((position) {
          controller.add(_ensurePosition(position));
        }, (error) {
          controller.addError(error);
        }, options);
      },
      onCancel: () {
        assert(watchId != null);
        _clearWatch(watchId);
      });

  return controller.stream;
}

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