ionic-native
Version:
Native plugin wrappers for Cordova and Ionic with TypeScript, ES6+, Promise and Observable support
93 lines • 4.14 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var plugin_1 = require('./plugin');
var Observable_1 = require('rxjs/Observable');
/**
* @name Geolocation
* @description
* This plugin provides information about the device's location, such as latitude and longitude. Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs.
*
* This API is based on the W3C Geolocation API Specification, and only executes on devices that don't already provide an implementation.
*
* @usage
*
* ```typescript
* import { Geolocation } from 'ionic-native';
*
*
* Geolocation.getCurrentPosition().then((resp) => {
* // resp.coords.latitude
* // resp.coords.longitude
* }).catch((error) => {
* console.log('Error getting location', error);
* });
*
* let watch = Geolocation.watchPosition();
* watch.subscribe((data) => {
* // data can be a set of coordinates, or an error (if an error occurred).
* // data.coords.latitude
* // data.coords.longitude
* });
* ```
* @interfaces
* Coordinates
* Geoposition
* PositionError
* GeolocationOptions
*/
var Geolocation = (function () {
function Geolocation() {
}
/**
* Get the device's current position.
*
* @param {GeolocationOptions} options The [geolocation options](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions).
* @returns {Promise<Geoposition>} Returns a Promise that resolves with the [position](https://developer.mozilla.org/en-US/docs/Web/API/Position) of the device, or rejects with an error.
*/
Geolocation.getCurrentPosition = function (options) { return; };
/**
* Watch the current device's position. Clear the watch by unsubscribing from
* Observable changes.
*
* ```typescript
* var subscription = Geolocation.watchPosition()
* .filter((p) => p.coords !== undefined) //Filter Out Errors
* .subscribe(position => {
* console.log(position.coords.longitude + ' ' + position.coords.latitude);
* });
*
* // To stop notifications
* subscription.unsubscribe();
* ```
*
* @param {GeolocationOptions} options The [geolocation options](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions).
* @returns {Observable<Geoposition>} Returns an Observable that notifies with the [position](https://developer.mozilla.org/en-US/docs/Web/API/Position) of the device, or errors.
*/
Geolocation.watchPosition = function (options) {
return new Observable_1.Observable(function (observer) {
var watchId = navigator.geolocation.watchPosition(observer.next.bind(observer), observer.next.bind(observer), options);
return function () { return navigator.geolocation.clearWatch(watchId); };
});
};
__decorate([
plugin_1.Cordova({
callbackOrder: 'reverse'
})
], Geolocation, "getCurrentPosition", null);
Geolocation = __decorate([
plugin_1.Plugin({
pluginName: 'Geolocation',
plugin: 'cordova-plugin-geolocation',
pluginRef: 'navigator.geolocation',
repo: 'https://github.com/apache/cordova-plugin-geolocation'
})
], Geolocation);
return Geolocation;
}());
exports.Geolocation = Geolocation;
//# sourceMappingURL=geolocation.js.map
;