From 4a8650e45e99f5dc2b82e43e871f71703c5db9fd Mon Sep 17 00:00:00 2001 From: Ibrahim Hadeed Date: Sat, 11 Jun 2016 10:19:06 -0400 Subject: [PATCH] fix(geolocation): fix watchPosition() closes #164 --- src/plugins/geolocation.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/plugins/geolocation.ts b/src/plugins/geolocation.ts index fea2a97dc..8c059f993 100644 --- a/src/plugins/geolocation.ts +++ b/src/plugins/geolocation.ts @@ -1,7 +1,7 @@ import {Plugin, Cordova} from './plugin'; import {Observable} from 'rxjs/Observable'; -declare var window; +declare var navigator: any; export interface Coordinates { /** @@ -151,10 +151,13 @@ export class Geolocation { * @param {GeolocationOptions} options The [geolocation options](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions). * @return Returns an Observable that notifies with the [position](https://developer.mozilla.org/en-US/docs/Web/API/Position) of the device, or errors. */ - @Cordova({ - callbackOrder: 'reverse', - observable: true, - clearFunction: 'clearWatch' - }) - static watchPosition(options?: GeolocationOptions): Observable { return; } + static watchPosition(options?: GeolocationOptions): Observable { + return new Observable( + (observer: any) => { + let cb = (data: Geoposition) => observer.next(data); + let watchId = navigator.geolocation.watchPosition(cb, options); + return () => navigator.geolocation.clearWatch(watchId); + } + ); + } }