mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
Device motion
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {IonicView} from 'ionic/ionic';
|
||||
import {IonicView, DeviceMotion} from 'ionic/ionic';
|
||||
|
||||
|
||||
@IonicView({
|
||||
@@ -10,9 +10,38 @@ import {IonicView} from 'ionic/ionic';
|
||||
<ion-title>Device Motion</ion-title>
|
||||
</ion-navbar>
|
||||
<ion-content class="padding">
|
||||
<button primary outline (click)="doDeviceMotion()">Get Device Motion</button>
|
||||
<div *ng-if="accel">
|
||||
x: <b>{{accel.x}}</b><br>
|
||||
y: <b>{{accel.y}}</b><br>
|
||||
z: <b>{{accel.z}}</b><br>
|
||||
</div>
|
||||
<button primary outline (click)="doDeviceMotionWatch()">Track Device Motion</button>
|
||||
<div *ng-if="accelTrack">
|
||||
x: <b>{{accelTrack.x}}</b><br>
|
||||
y: <b>{{accelTrack.y}}</b><br>
|
||||
z: <b>{{accelTrack.z}}</b><br>
|
||||
</div>
|
||||
</ion-content>
|
||||
`
|
||||
})
|
||||
export class DeviceMotionPage {
|
||||
|
||||
doDeviceMotion() {
|
||||
let device = DeviceMotion.getCurrentAcceleration().then((resp) => {
|
||||
console.log('Device motion', resp);
|
||||
this.accel = resp.accelerationIncludingGravity;
|
||||
}, (err) => {
|
||||
console.log('Device err', err);
|
||||
});
|
||||
console.log('Got device', device);
|
||||
}
|
||||
doDeviceMotionWatch() {
|
||||
let device = DeviceMotion.watchAcceleration().source.subscribe((resp) => {
|
||||
console.log('Device motion track', resp);
|
||||
this.accelTrack = resp.accelerationIncludingGravity;
|
||||
}, (err) => {
|
||||
console.log('Device err', err);
|
||||
});
|
||||
console.log('Got device', device);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {IonicView} from 'ionic/ionic';
|
||||
import {IonicView, Device} from 'ionic/ionic';
|
||||
|
||||
|
||||
@IonicView({
|
||||
|
||||
Reference in New Issue
Block a user