2015-12-01 10:17:55 +08:00
var _ _decorate = ( this && this . _ _decorate ) || function ( decorators , target , key , desc ) {
2015-12-02 08:47:24 +08:00
var c = arguments . length , r = c < 3 ? target : desc === null ? desc = Object . getOwnPropertyDescriptor ( target , key ) : desc , d ;
if ( typeof Reflect === "object" && typeof Reflect . decorate === "function" ) r = Reflect . decorate ( decorators , target , key , desc ) ;
else for ( var i = decorators . length - 1 ; i >= 0 ; i -- ) if ( d = decorators [ i ] ) r = ( c < 3 ? d ( r ) : c > 3 ? d ( target , key , r ) : d ( target , key ) ) || r ;
return c > 3 && r && Object . defineProperty ( target , key , r ) , r ;
2015-11-30 09:54:45 +08:00
} ;
var plugin _1 = require ( './plugin' ) ;
2016-02-16 00:55:31 +08:00
var Observable _1 = require ( 'rxjs/Observable' ) ;
2016-02-06 05:06:03 +08:00
/ * *
* Get geolocation data .
*
* @ usage
* ` ` ` js
* Geolocation . getCurrentPosition ( ) . then ( ( resp ) => {
* //resp.coords.latitude
* //resp.coords.longitude
* } )
*
* let watch = Geolocation . watchPosition ( ) ;
2016-02-09 03:06:22 +08:00
* watch . subscribe ( ( data ) => {
2016-02-06 05:06:03 +08:00
* //data.coords.latitude
* //data.coords.longitude
* } )
* ` ` `
* /
2015-12-01 03:27:25 +08:00
var Geolocation = ( function ( ) {
function Geolocation ( ) {
2015-11-30 09:54:45 +08:00
}
2016-02-16 00:55:31 +08:00
/ * *
* Get the device ' s current position .
*
* @ param { GeolocationOptions } options The [ geolocation options ] ( https : //developer.mozilla.org/en-US/docs/Web/API/PositionOptions).
* @ return Returns a Promise that resolves with the [ position ] ( https : //developer.mozilla.org/en-US/docs/Web/API/Position) of the device, or rejects with an error.
* /
Geolocation . getCurrentPosition = function ( options ) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise ( function ( res , rej ) { } ) ;
} ;
/ * *
* Watch the current device ' s position . Clear the watch by unsubscribing from
* Observable changes .
*
* ` ` `
* var subscription = Geolocation . watchPosition ( ) . subscribe ( position => {
* console . log ( position . coords . longitude + ' ' + position . coords . latitude ) ;
* } ) ;
*
* // To stop notifications
* subscription . unsubscribe ( ) ;
* ` ` `
*
* @ 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.
* /
Geolocation . watchPosition = function ( options ) {
// This Observable is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Observable, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Observable _1 . Observable ( function ( observer ) { } ) ;
} ;
2015-12-01 02:34:54 +08:00
;
2015-12-02 08:47:24 +08:00
_ _decorate ( [
plugin _1 . Cordova ( )
] , Geolocation , "getCurrentPosition" , null ) ;
_ _decorate ( [
plugin _1 . Cordova ( {
callbackOrder : 'reverse' ,
observable : true ,
2016-02-09 03:06:22 +08:00
clearFunction : 'clearWatch'
2015-12-02 08:47:24 +08:00
} )
] , Geolocation , "watchPosition" , null ) ;
2015-12-01 03:27:25 +08:00
Geolocation = _ _decorate ( [
2015-11-30 09:54:45 +08:00
plugin _1 . Plugin ( {
name : 'Geolocation' ,
plugin : 'cordova-plugin-geolocation' ,
pluginRef : 'navigator.geolocation'
} )
2015-12-01 03:27:25 +08:00
] , Geolocation ) ;
return Geolocation ;
2015-11-30 09:54:45 +08:00
} ) ( ) ;
2015-12-01 03:27:25 +08:00
exports . Geolocation = Geolocation ;
2015-12-01 02:34:54 +08:00
//# sourceMappingURL=geolocation.js.map