API Reference 0.5.1+4rikulo_geolocationGeolocation

Geolocation class

Capture device motion in x, y, and z direction.

class Geolocation {
 js.Proxy _geolocation;

 factory Geolocation() => geolocation;

 Geolocation._internal() {
   if (device == null)
     throw new StateError('device is not ready yet.');
   js.scoped(() {
     _geolocation = js.context.navigator.geolocation;
     js.retain(_geolocation);
   });
 }

 /**
  * Returns the current Position of this device.
  * The Position is returned via the success callback function.
  */
 void getCurrentPosition(GeolocationSuccessCB success,
                   [GeolocationErrorCB error, GeolocationOptions options]) {
   js.scoped(() {
     var s0 = (p) => success(new Position.fromProxy(p));
     var e0 = (p) => error(new PositionError.fromProxy(p));
     List jsfns = JSUtil.newCallbackOnceGroup("geo", [s0, e0], [1, 1]);
     var ok = jsfns[0];
     var fail = jsfns[1];
     _geolocation.getCurrentPosition(ok, fail);
   });
 }

 /**
  * Register functions to get the Position information in a regular
  * interval. This method returns an associated watchID which you can use to
  * clear this watch via [clearWatch] method.
  *
  * + [success] - success callback function.
  * + [error] - error callback function.
  * + [options] - optional parameter.
  */
 watchPosition(GeolocationSuccessCB success,
                   [GeolocationErrorCB error, GeolocationOptions options]) {
   return js.scoped(() {
     var s0 = (p) => success(new Position.fromProxy(p));
     var e0 = error == null ?
         null : (p) => error(new PositionError.fromProxy(p));
     var ok = new js.Callback.many(s0);
     var fail = e0 == null ? null : new js.Callback.many(e0);
     var opts = options == null ? null : js.map(options._toMap());
     var id = "geo_${geolocation.watchPosition(ok, fail, opts)}";
     JSUtil.addCallbacks(id, [ok, fail]);
     return id;
   });
 }

 /**
  * Stop watching the Position that was associated with the specified
  * watchID.
  *
  * + [watchID] - the watch ID got from [watchPosition] method.
  */
 void clearWatch(var watchID) {
   js.scoped(() {
     _geolocation.clearWatch(watchID.substring(4));
     JSUtil.delCallbacks(watchID);
   });
 }
}

Constructors

factory Geolocation() #

factory Geolocation() => geolocation;

Methods

void clearWatch(watchID) #

Stop watching the Position that was associated with the specified watchID.

void clearWatch(var watchID) {
 js.scoped(() {
   _geolocation.clearWatch(watchID.substring(4));
   JSUtil.delCallbacks(watchID);
 });
}

void getCurrentPosition(GeolocationSuccessCB success, [GeolocationErrorCB error, GeolocationOptions options]) #

Returns the current Position of this device. The Position is returned via the success callback function.

void getCurrentPosition(GeolocationSuccessCB success,
                 [GeolocationErrorCB error, GeolocationOptions options]) {
 js.scoped(() {
   var s0 = (p) => success(new Position.fromProxy(p));
   var e0 = (p) => error(new PositionError.fromProxy(p));
   List jsfns = JSUtil.newCallbackOnceGroup("geo", [s0, e0], [1, 1]);
   var ok = jsfns[0];
   var fail = jsfns[1];
   _geolocation.getCurrentPosition(ok, fail);
 });
}

dynamic watchPosition(GeolocationSuccessCB success, [GeolocationErrorCB error, GeolocationOptions options]) #

Register functions to get the Position information in a regular interval. This method returns an associated watchID which you can use to clear this watch via clearWatch method.

  • success - success callback function.
  • error - error callback function.
  • options - optional parameter.
watchPosition(GeolocationSuccessCB success,
                 [GeolocationErrorCB error, GeolocationOptions options]) {
 return js.scoped(() {
   var s0 = (p) => success(new Position.fromProxy(p));
   var e0 = error == null ?
       null : (p) => error(new PositionError.fromProxy(p));
   var ok = new js.Callback.many(s0);
   var fail = e0 == null ? null : new js.Callback.many(e0);
   var opts = options == null ? null : js.map(options._toMap());
   var id = "geo_${geolocation.watchPosition(ok, fail, opts)}";
   JSUtil.addCallbacks(id, [ok, fail]);
   return id;
 });
}