W3cubDocs

/Dart 2

getCurrentPosition method

Future<Geoposition> getCurrentPosition ({bool enableHighAccuracy, Duration timeout, Duration maximumAge })

Implementation

Future<Geoposition> getCurrentPosition(
    {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;
  }
  var completer = new Completer<Geoposition>();
  try {
    _getCurrentPosition((position) {
      completer.complete(_ensurePosition(position));
    }, (error) {
      completer.completeError(error);
    }, options);
  } catch (e, stacktrace) {
    completer.completeError(e, stacktrace);
  }
  return completer.future;
}

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