UNPKG

@ionic-native/geolocation

Version:

Ionic Native - Native plugins for ionic apps

54 lines (49 loc) 2.53 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib = require('tslib'); var core$1 = require('@angular/core'); var core = require('@ionic-native/core'); var rxjs = require('rxjs'); var Geolocation = /** @class */ (function (_super) { tslib.__extends(Geolocation, _super); function Geolocation() { return _super !== null && _super.apply(this, arguments) || this; } Geolocation.prototype.getCurrentPosition = function (options) { return core.cordova(this, "getCurrentPosition", { "callbackOrder": "reverse" }, arguments); }; /** * Watch the current device's position. Clear the watch by unsubscribing from * Observable changes. * * ```typescript * const subscription = this.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 | PositionError>} Returns an Observable that notifies with the [position](https://developer.mozilla.org/en-US/docs/Web/API/Position) of the device, or errors. */ Geolocation.prototype.watchPosition = function (options) { return new rxjs.Observable(function (observer) { var watchId = navigator.geolocation.watchPosition(observer.next.bind(observer), observer.next.bind(observer), options); return function () { return navigator.geolocation.clearWatch(watchId); }; }); }; Geolocation.pluginName = "Geolocation"; Geolocation.plugin = "cordova-plugin-geolocation"; Geolocation.pluginRef = "navigator.geolocation"; Geolocation.repo = "https://github.com/apache/cordova-plugin-geolocation"; Geolocation.install = "ionic cordova plugin add cordova-plugin-geolocation --variable GEOLOCATION_USAGE_DESCRIPTION=\"To locate you\""; Geolocation.installVariables = ["GEOLOCATION_USAGE_DESCRIPTION"]; Geolocation.platforms = ["Amazon Fire OS", "Android", "Browser", "iOS", "Windows"]; Geolocation.decorators = [ { type: core$1.Injectable } ]; return Geolocation; }(core.IonicNativePlugin)); exports.Geolocation = Geolocation;