UNPKG

2.53 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var tslib = require('tslib');
6var core$1 = require('@angular/core');
7var core = require('@ionic-native/core');
8var rxjs = require('rxjs');
9
10var Geolocation = /** @class */ (function (_super) {
11 tslib.__extends(Geolocation, _super);
12 function Geolocation() {
13 return _super !== null && _super.apply(this, arguments) || this;
14 }
15 Geolocation.prototype.getCurrentPosition = function (options) { return core.cordova(this, "getCurrentPosition", { "callbackOrder": "reverse" }, arguments); };
16 /**
17 * Watch the current device's position. Clear the watch by unsubscribing from
18 * Observable changes.
19 *
20 * ```typescript
21 * const subscription = this.geolocation.watchPosition()
22 * .filter((p) => p.coords !== undefined) //Filter Out Errors
23 * .subscribe(position => {
24 * console.log(position.coords.longitude + ' ' + position.coords.latitude);
25 * });
26 *
27 * // To stop notifications
28 * subscription.unsubscribe();
29 * ```
30 *
31 * @param {GeolocationOptions} options The [geolocation options](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions).
32 * @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.
33 */
34 Geolocation.prototype.watchPosition = function (options) {
35 return new rxjs.Observable(function (observer) {
36 var watchId = navigator.geolocation.watchPosition(observer.next.bind(observer), observer.next.bind(observer), options);
37 return function () { return navigator.geolocation.clearWatch(watchId); };
38 });
39 };
40 Geolocation.pluginName = "Geolocation";
41 Geolocation.plugin = "cordova-plugin-geolocation";
42 Geolocation.pluginRef = "navigator.geolocation";
43 Geolocation.repo = "https://github.com/apache/cordova-plugin-geolocation";
44 Geolocation.install = "ionic cordova plugin add cordova-plugin-geolocation --variable GEOLOCATION_USAGE_DESCRIPTION=\"To locate you\"";
45 Geolocation.installVariables = ["GEOLOCATION_USAGE_DESCRIPTION"];
46 Geolocation.platforms = ["Amazon Fire OS", "Android", "Browser", "iOS", "Windows"];
47 Geolocation.decorators = [
48 { type: core$1.Injectable }
49 ];
50 return Geolocation;
51}(core.IonicNativePlugin));
52
53exports.Geolocation = Geolocation;