mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
Geolocation
This commit is contained in:
@ -3,6 +3,23 @@ import * as Rx from 'rx';
|
|||||||
import * as util from 'ionic/util';
|
import * as util from 'ionic/util';
|
||||||
import {NativePlugin} from '../plugin';
|
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({
|
@NativePlugin({
|
||||||
name: 'Geolocation',
|
name: 'Geolocation',
|
||||||
platforms: ['ios', 'android', 'web'],
|
platforms: ['ios', 'android', 'web'],
|
||||||
@ -11,6 +28,9 @@ import {NativePlugin} from '../plugin';
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
export class Geolocation {
|
export class Geolocation {
|
||||||
|
/**
|
||||||
|
* Get the current GPS location.
|
||||||
|
*/
|
||||||
static getCurrentPosition(options) {
|
static getCurrentPosition(options) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
navigator.geolocation.getCurrentPosition(function (result) {
|
navigator.geolocation.getCurrentPosition(function (result) {
|
||||||
@ -21,6 +41,9 @@ export class Geolocation {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch for location changes.
|
||||||
|
*/
|
||||||
static watchPosition(options) {
|
static watchPosition(options) {
|
||||||
let watchID;
|
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) {
|
static clearWatch(watchID) {
|
||||||
return navigator.geolocation.clearWatch(watchID);
|
return navigator.geolocation.clearWatch(watchID);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user