Dart Documentationchrome.locationChromeLocation

ChromeLocation class

class ChromeLocation extends ChromeApi {
 static final JsObject _location = chrome['location'];

 ChromeLocation._();

 bool get available => _location != null;

 /**
  * Starts a location watching request. If there is another location watching
  * request with the same name (or no name if none is specified), it will be
  * cancelled and replaced by this request.
  * [name]: Optional name to identify this request. Defaults to the empty
  * string.
  * [requestInfo]: Optional parameters for this request.
  */
 void watchLocation(String name, WatchLocationRequestInfo requestInfo) {
   if (_location == null) _throwNotAvailable();

   _location.callMethod('watchLocation', [name, jsify(requestInfo)]);
 }

 /**
  * Ends a location watching request.
  * [name]: Optional name to identify the request to remove. Defaults to the
  * empty string.
  */
 void clearWatch(String name) {
   if (_location == null) _throwNotAvailable();

   _location.callMethod('clearWatch', [name]);
 }

 Stream<Location> get onLocationUpdate => _onLocationUpdate.stream;

 final ChromeStreamController<Location> _onLocationUpdate =
     new ChromeStreamController<Location>.oneArg(_location, 'onLocationUpdate', _createLocation);

 Stream<String> get onLocationError => _onLocationError.stream;

 final ChromeStreamController<String> _onLocationError =
     new ChromeStreamController<String>.oneArg(_location, 'onLocationError', selfConverter);

 void _throwNotAvailable() {
   throw new UnsupportedError("'chrome.location' is not available");
 }
}

Extends

ChromeApi > ChromeLocation

Properties

final bool available #

Returns true if the API is available. The common causes of an API not being avilable are:

  • a permission is missing in the application's manifest.json file
  • the API is defined on a newer version of Chrome then the current runtime
docs inherited from ChromeApi
bool get available => _location != null;

final Stream<String> onLocationError #

Stream<String> get onLocationError => _onLocationError.stream;

final Stream<Location> onLocationUpdate #

Stream<Location> get onLocationUpdate => _onLocationUpdate.stream;

Methods

void clearWatch(String name) #

Ends a location watching request. name: Optional name to identify the request to remove. Defaults to the empty string.

void clearWatch(String name) {
 if (_location == null) _throwNotAvailable();

 _location.callMethod('clearWatch', [name]);
}

void watchLocation(String name, WatchLocationRequestInfo requestInfo) #

Starts a location watching request. If there is another location watching request with the same name (or no name if none is specified), it will be cancelled and replaced by this request. name: Optional name to identify this request. Defaults to the empty string. requestInfo: Optional parameters for this request.

void watchLocation(String name, WatchLocationRequestInfo requestInfo) {
 if (_location == null) _throwNotAvailable();

 _location.callMethod('watchLocation', [name, jsify(requestInfo)]);
}