Dart API Referencedart:htmlGeolocation

Geolocation class

@DocsEditable
@DomName('Geolocation')
class Geolocation native "Geolocation" {

 @DomName('Geolocation.getCurrentPosition')
 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 {
     $dom_getCurrentPosition(
         (position) {
           completer.complete(_ensurePosition(position));
         },
         (error) {
           completer.completeError(error);
         },
         options);
   } catch (e, stacktrace) {
     completer.completeError(e, stacktrace);
   }
   return completer.future;
 }

 @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;
   var controller;
   controller = new StreamController<Geoposition>(
     onListen: () {
       assert(watchId == null);
       watchId = $dom_watchPosition(
           (position) {
             controller.add(_ensurePosition(position));
           },
           (error) {
             controller.addError(error);
           },
           options);
     },
     onCancel: () {
       assert(watchId != null);
       $dom_clearWatch(watchId);
     });

   return controller.stream;
 }

 Geoposition _ensurePosition(domPosition) {
   try {
     // Firefox may throw on this.
     if (domPosition is Geoposition) {
       return domPosition;
     }
   } catch(e) {}
   return new _GeopositionWrapper(domPosition);
 }


 @JSName('clearWatch')
 @DomName('Geolocation.clearWatch')
 @DocsEditable
 void $dom_clearWatch(int watchID) native;

 @JSName('getCurrentPosition')
 @DomName('Geolocation.getCurrentPosition')
 @DocsEditable
 void $dom_getCurrentPosition(_PositionCallback successCallback, [_PositionErrorCallback errorCallback, Object options]) native;

 @JSName('watchPosition')
 @DomName('Geolocation.watchPosition')
 @DocsEditable
 int $dom_watchPosition(_PositionCallback successCallback, [_PositionErrorCallback errorCallback, Object options]) native;
}

Extends

Interceptor > Geolocation

Properties

final int hashCode #

inherited from Interceptor

Get a hash code for this object.

All objects have hash codes. Hash codes are guaranteed to be the same for objects that are equal when compared using the equality operator ==. Other than that there are no guarantees about the hash codes. They will not be consistent between runs and there are no distribution guarantees.

If a subclass overrides hashCode it should override the equality operator as well to maintain consistency.

docs inherited from Object
int get hashCode => Primitives.objectHashCode(this);

final Type runtimeType #

inherited from Interceptor

A representation of the runtime type of the object.

docs inherited from Object
Type get runtimeType => getRuntimeType(this);

Operators

bool operator ==(other) #

inherited from Interceptor

The equality operator.

The default behavior for all Objects is to return true if and only if this and other are the same object.

If a subclass overrides the equality operator it should override the hashCode method as well to maintain consistency.

docs inherited from Object
bool operator ==(other) => identical(this, other);

Methods

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

Acquires the user's current position via a new position object. If this fails, errorCallback is invoked with an nsIDOMGeoPositionError argument.

Parameters
successCallback
An nsIDOMGeoPositionCallback to be called when the current position is available.
errorCallback
An nsIDOMGeoPositionErrorCallback that is called if an error occurs while retrieving the position; this parameter is optional.
options
An nsIDOMGeoPositionOptions object specifying options; this parameter is optional.
@DomName('Geolocation.getCurrentPosition')
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 {
   $dom_getCurrentPosition(
       (position) {
         completer.complete(_ensurePosition(position));
       },
       (error) {
         completer.completeError(error);
       },
       options);
 } catch (e, stacktrace) {
   completer.completeError(e, stacktrace);
 }
 return completer.future;
}

dynamic noSuchMethod(Invocation invocation) #

inherited from Interceptor

noSuchMethod is invoked when users invoke a non-existant method on an object. The name of the method and the arguments of the invocation are passed to noSuchMethod in an Invocation. If noSuchMethod returns a value, that value becomes the result of the original invocation.

The default behavior of noSuchMethod is to throw a noSuchMethodError.

docs inherited from Object
dynamic noSuchMethod(Invocation invocation) {
 throw new NoSuchMethodError(
     this,
     _symbolToString(invocation.memberName),
     invocation.positionalArguments,
     _symbolMapToStringMap(invocation.namedArguments));
}

String toString() #

inherited from Interceptor

Returns a string representation of this object.

docs inherited from Object
String toString() => Primitives.objectToString(this);

Stream<Geoposition> watchPosition({bool enableHighAccuracy, Duration timeout, Duration maximumAge}) #

Similar to getCurrentPosition(), except it continues to call the callback with updated position information periodically until clearWatch() is called.

Parameters
successCallback
An nsIDOMGeoPositionCallback that is to be called whenever new position information is available.
errorCallback
An nsIDOMGeoPositionErrorCallback to call when an error occurs; this is an optional parameter.
options
An nsIDOMGeoPositionOptions object specifying options; this parameter is optional.
Return value

An ID number that can be used to reference the watcher in the future when calling clearWatch().

@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;
 var controller;
 controller = new StreamController<Geoposition>(
   onListen: () {
     assert(watchId == null);
     watchId = $dom_watchPosition(
         (position) {
           controller.add(_ensurePosition(position));
         },
         (error) {
           controller.addError(error);
         },
         options);
   },
   onCancel: () {
     assert(watchId != null);
     $dom_clearWatch(watchId);
   });

 return controller.stream;
}

void $dom_clearWatch(int watchID) #

When the clearWatch() method is called, the watch() process stops calling for new position identifiers and cease invoking callbacks.
@JSName('clearWatch')
@DomName('Geolocation.clearWatch')
@DocsEditable
void $dom_clearWatch(int watchID) native;

void $dom_getCurrentPosition(_PositionCallback successCallback, [_PositionErrorCallback errorCallback, Object options]) #

Acquires the user's current position via a new position object. If this fails, errorCallback is invoked with an nsIDOMGeoPositionError argument.

Parameters
successCallback
An nsIDOMGeoPositionCallback to be called when the current position is available.
errorCallback
An nsIDOMGeoPositionErrorCallback that is called if an error occurs while retrieving the position; this parameter is optional.
options
An nsIDOMGeoPositionOptions object specifying options; this parameter is optional.
@JSName('getCurrentPosition')
@DomName('Geolocation.getCurrentPosition')
@DocsEditable
void $dom_getCurrentPosition(_PositionCallback successCallback, [_PositionErrorCallback errorCallback, Object options]) native;

int $dom_watchPosition(_PositionCallback successCallback, [_PositionErrorCallback errorCallback, Object options]) #

Similar to getCurrentPosition(), except it continues to call the callback with updated position information periodically until clearWatch() is called.

Parameters
successCallback
An nsIDOMGeoPositionCallback that is to be called whenever new position information is available.
errorCallback
An nsIDOMGeoPositionErrorCallback to call when an error occurs; this is an optional parameter.
options
An nsIDOMGeoPositionOptions object specifying options; this parameter is optional.
Return value

An ID number that can be used to reference the watcher in the future when calling clearWatch().

@JSName('watchPosition')
@DomName('Geolocation.watchPosition')
@DocsEditable
int $dom_watchPosition(_PositionCallback successCallback, [_PositionErrorCallback errorCallback, Object options]) native;

This page includes content from the Mozilla Foundation that is graciously licensed under a Creative Commons: Attribution-Sharealike license. Mozilla has no other association with Dart or dartlang.org. We encourage you to improve the web by contributing to The Mozilla Developer Network.