UNPKG

2.32 kBTypeScriptView Raw
1import { Observable } from 'rxjs/Observable';
2export interface DeviceMotionAccelerationData {
3 /**
4 * Amount of acceleration on the x-axis. (in m/s^2)
5 */
6 x: number;
7 /**
8 * Amount of acceleration on the y-axis. (in m/s^2)
9 */
10 y: number;
11 /**
12 * Amount of acceleration on the z-axis. (in m/s^2)
13 */
14 z: number;
15 /**
16 * Creation timestamp in milliseconds.
17 */
18 timestamp: any;
19}
20export interface DeviceMotionAccelerometerOptions {
21 /**
22 * Requested period of calls to accelerometerSuccess with acceleration data in Milliseconds. Default: 10000
23 */
24 frequency?: number;
25}
26/**
27 * @name Device Motion
28 * @description
29 * Requires Cordova plugin: `cordova-plugin-device-motion`. For more info, please see the [Device Motion docs](https://github.com/apache/cordova-plugin-device-motion).
30 *
31 * @usage
32 * ```typescript
33 * import { DeviceMotion, DeviceMotionAccelerationData } from 'ionic-native';
34 *
35 *
36 * // Get the device current acceleration
37 * DeviceMotion.getCurrentAcceleration().then(
38 * (acceleration: DeviceMotionAccelerationData) => console.log(acceleration),
39 * (error: any) => console.log(error)
40 * );
41 *
42 * // Watch device acceleration
43 * var subscription = DeviceMotion.watchAcceleration().subscribe((acceleration: DeviceMotionAccelerationData) => {
44 * console.log(acceleration);
45 * });
46 *
47 * // Stop watch
48 * subscription.unsubscribe();
49 *
50 * ```
51 * @interfaces
52 * DeviceMotionAccelerationData
53 * DeviceMotionAccelerometerOptions
54 */
55export declare class DeviceMotion {
56 /**
57 * Get the current acceleration along the x, y, and z axes.
58 * @returns {Promise<DeviceMotionAccelerationData>} Returns object with x, y, z, and timestamp properties
59 */
60 static getCurrentAcceleration(): Promise<DeviceMotionAccelerationData>;
61 /**
62 * Watch the device acceleration. Clear the watch by unsubscribing from the observable.
63 * @param {AccelerometerOptions} options list of options for the accelerometer.
64 * @returns {Observable<DeviceMotionAccelerationData>} Observable returns an observable that you can subscribe to
65 */
66 static watchAcceleration(options?: DeviceMotionAccelerometerOptions): Observable<DeviceMotionAccelerationData>;
67}