2016-07-08 06:53:35 +08:00
|
|
|
import { Cordova, Plugin } from './plugin';
|
|
|
|
import { Observable } from 'rxjs/Observable';
|
|
|
|
|
2016-03-07 05:06:43 +08:00
|
|
|
|
|
|
|
export interface CompassHeading {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The heading in degrees from 0-359.99 at a single moment in time. (Number)
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
magneticHeading: number;
|
2016-03-07 05:06:43 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The heading relative to the geographic North Pole in degrees 0-359.99 at a single moment in time. A negative value indicates that the true heading can't be determined. (Number)
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
trueHeading: number;
|
2016-03-07 05:06:43 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The deviation in degrees between the reported heading and the true heading. (Number)
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
headingAccuracy: number;
|
2016-03-07 05:06:43 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The time at which this heading was determined. (DOMTimeStamp)
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
timestamp: any;
|
2016-03-07 05:06:43 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CompassOptions {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How often to retrieve the compass heading in milliseconds. (Number) (Default: 100)
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
frequency?: number;
|
2016-03-07 05:06:43 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The change in degrees required to initiate a watchHeading success callback. When this value is set, frequency is ignored. (Number)
|
|
|
|
*/
|
2016-04-30 11:56:49 +08:00
|
|
|
filter?: number;
|
2016-03-07 05:06:43 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-14 03:45:07 +08:00
|
|
|
* @name Device Orientation
|
2016-03-13 07:30:16 +08:00
|
|
|
* @description
|
2016-03-07 05:06:43 +08:00
|
|
|
* Requires Cordova plugin: `cordova-plugin-device-orientation`. For more info, please see the [Device Orientation docs](https://github.com/apache/cordova-plugin-device-orientation).
|
|
|
|
*
|
|
|
|
* @usage
|
2016-07-20 23:17:09 +08:00
|
|
|
* ```typescript
|
|
|
|
* import { DeviceOrientation } from 'ionic-native';
|
2016-03-25 01:00:18 +08:00
|
|
|
*
|
|
|
|
*
|
2016-03-09 02:29:03 +08:00
|
|
|
* // Get the device current compass heading
|
|
|
|
* DeviceOrientation.getCurrentHeading().then(
|
2016-07-20 23:17:09 +08:00
|
|
|
* (data: CompassHeading) => console.log(data),
|
|
|
|
* (error: any) => console.log(error)
|
2016-03-09 02:29:03 +08:00
|
|
|
* );
|
|
|
|
*
|
|
|
|
* // Watch the device compass heading change
|
|
|
|
* var subscription = DeviceOrientation.watchHeading().subscribe(
|
2016-07-20 23:17:09 +08:00
|
|
|
* (data: CompassHeading) => console.log(data)
|
2016-03-09 02:29:03 +08:00
|
|
|
* );
|
|
|
|
*
|
|
|
|
* // Stop watching heading change
|
|
|
|
* subscription.unsubscribe();
|
2016-03-07 05:06:43 +08:00
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
@Plugin({
|
2016-03-13 07:30:16 +08:00
|
|
|
plugin: 'cordova-plugin-device-orientation',
|
|
|
|
pluginRef: 'navigator.compass',
|
|
|
|
repo: 'https://github.com/apache/cordova-plugin-device-orientation'
|
2016-03-07 05:06:43 +08:00
|
|
|
})
|
|
|
|
export class DeviceOrientation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current compass heading.
|
|
|
|
* @returns {Promise<CompassHeading>}
|
|
|
|
*/
|
|
|
|
@Cordova()
|
2016-04-30 11:56:49 +08:00
|
|
|
static getCurrentHeading(): Promise<CompassHeading> { return; }
|
2016-03-07 05:06:43 +08:00
|
|
|
|
|
|
|
/**
|
2016-03-09 02:26:55 +08:00
|
|
|
* Get the device current heading at a regular interval
|
|
|
|
*
|
|
|
|
* Stop the watch by unsubscribing from the observable
|
2016-07-09 03:19:13 +08:00
|
|
|
* @param {CompassOptions} options Options for compass. Frequency and Filter. Optional
|
|
|
|
* @returns {Observable<CompassHeading>} Returns an observable that contains the compass heading
|
2016-03-07 05:06:43 +08:00
|
|
|
*/
|
|
|
|
@Cordova({
|
2016-03-09 02:26:55 +08:00
|
|
|
callbackOrder: 'reverse',
|
|
|
|
observable: true,
|
2016-06-10 04:50:54 +08:00
|
|
|
clearFunction: 'clearWatch'
|
2016-03-07 05:06:43 +08:00
|
|
|
})
|
2016-04-30 11:56:49 +08:00
|
|
|
static watchHeading(options?: CompassOptions): Observable<CompassHeading> { return; }
|
2016-03-07 05:06:43 +08:00
|
|
|
|
|
|
|
}
|