Device motion

This commit is contained in:
Max Lynch
2015-09-09 11:10:11 -05:00
parent eb40b6f6f5
commit e166e2217b
3 changed files with 76 additions and 34 deletions

View File

@@ -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);
}
}

View File

@@ -1,4 +1,4 @@
import {IonicView} from 'ionic/ionic';
import {IonicView, Device} from 'ionic/ionic';
@IonicView({