mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 19:57:22 +08:00
Revert "Temporarily removing native plugins"
This reverts commit 81d907e8b95eb3286200a5c5ab479bbade56f03b.
This commit is contained in:
46
ionic/native/geolocation/geolocation.ts
Normal file
46
ionic/native/geolocation/geolocation.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import * as Rx from 'rx';
|
||||
|
||||
import * as util from 'ionic/util';
|
||||
import {NativePlugin} from '../plugin';
|
||||
|
||||
@NativePlugin({
|
||||
name: 'Geolocation',
|
||||
platforms: {
|
||||
cordova: 'cordova-plugin-geolocation'
|
||||
}
|
||||
})
|
||||
export class Geolocation {
|
||||
static getCurrentPosition(options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
navigator.geolocation.getCurrentPosition(function (result) {
|
||||
resolve(result);
|
||||
}, function (err) {
|
||||
reject(err);
|
||||
}, options);
|
||||
});
|
||||
}
|
||||
|
||||
static watchPosition(options) {
|
||||
let watchID;
|
||||
|
||||
let source = Rx.Observable.create((observer) => {
|
||||
watchID = navigator.geolocation.watchPosition(function (result) {
|
||||
observer.onNext(result)
|
||||
}, function(err) {
|
||||
observer.onError(err, observer);
|
||||
}, options);
|
||||
})
|
||||
|
||||
return {
|
||||
source: source,
|
||||
watchID: watchID,
|
||||
clear: () => {
|
||||
navigator.geolocation.clearWatch(watchID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static clearWatch(watchID) {
|
||||
return navigator.geolocation.clearWatch(watchID);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user