From fe612028a016628d1e171bcc193153fd21b15ccf Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Mon, 28 Sep 2015 14:02:45 -0500 Subject: [PATCH] Geolocation --- ionic/platform/geolocation/geolocation.ts | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/ionic/platform/geolocation/geolocation.ts b/ionic/platform/geolocation/geolocation.ts index 3d67112c68..a768b0f077 100644 --- a/ionic/platform/geolocation/geolocation.ts +++ b/ionic/platform/geolocation/geolocation.ts @@ -3,6 +3,23 @@ import * as Rx from 'rx'; import * as util from 'ionic/util'; import {NativePlugin} from '../plugin'; +/** + * Get geolocation data. + * + * @usage + * ```js + * Geolocation.getCurrentPosition().then((resp) => { + * //resp.coords.latitude + * //resp.coords.longitude + * }) + * + * let watch = Geolocation.watchPosition(); + * watch.source.subscribe((data) => { + * //data.coords.latitude + * //data.coords.longitude + * }) + * ``` + */ @NativePlugin({ name: 'Geolocation', platforms: ['ios', 'android', 'web'], @@ -11,6 +28,9 @@ import {NativePlugin} from '../plugin'; } }) export class Geolocation { + /** + * Get the current GPS location. + */ static getCurrentPosition(options) { return new Promise((resolve, reject) => { navigator.geolocation.getCurrentPosition(function (result) { @@ -21,6 +41,9 @@ export class Geolocation { }); } + /** + * Watch for location changes. + */ static watchPosition(options) { let watchID; @@ -41,6 +64,10 @@ export class Geolocation { } } + /** + * Clear a specific watch by watch ID. Generally, you'll call + * clear() on the returned watch from `getCurrentPosition` or `watchPosition` above. + */ static clearWatch(watchID) { return navigator.geolocation.clearWatch(watchID); }