Skip to content

Commit

Permalink
fix(geolocation): fix watchPosition()
Browse files Browse the repository at this point in the history
closes #164
  • Loading branch information
ihadeed committed Jun 11, 2016
1 parent a15fb01 commit 4a8650e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/plugins/geolocation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Plugin, Cordova} from './plugin';
import {Observable} from 'rxjs/Observable';

declare var window;
declare var navigator: any;

export interface Coordinates {
/**
Expand Down Expand Up @@ -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<Geoposition> { return; }
static watchPosition(options?: GeolocationOptions): Observable<Geoposition> {
return new Observable<Geoposition>(
(observer: any) => {
let cb = (data: Geoposition) => observer.next(data);
let watchId = navigator.geolocation.watchPosition(cb, options);
return () => navigator.geolocation.clearWatch(watchId);
}
);
}
}

0 comments on commit 4a8650e

Please sign in to comment.