我有一个ionic2的应用程序,我想用陀螺离子本地和科尔多瓦-插件陀螺这样tutoriel:
https://ionicframework.com/docs/native/gyroscope/
但我有这个错误
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'watch' of undefined
TypeError: Cannot read property 'watch' of undefined
at Observable._subscribe
...
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Gyroscope, GyroscopeOrientation, GyroscopeOptions } from '@ionic-native/gyroscope';
import { Platform } from 'ionic-angular';
import {geoCompassService} from '../../services/geocompass'
import * as Leaflet from "leaflet";
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage{
pointGps:any;
angle:any;
distance:any;
orientation:any;
constructor(private platform: Platform,
public navCtrl: NavController,
public _geoCompassService:geoCompassService,
private gyroscope: Gyroscope) {
platform.ready().then(() => {
console.log("platform ready !!!");
this.pointGps=this._geoCompassService.getPointGps();
this.angle = (Math.atan2(0,1) - Math.atan2(( this.pointGps.coordB.lng - this.pointGps.coordA.lng), ( this.pointGps.coordB.lat - this.pointGps.coordA.lat)))*180/Math.PI+180;
this.distance = Leaflet.latLng( this.pointGps.coordA).distanceTo(this.pointGps.coordB);
//Gyro
let options: GyroscopeOptions = {
frequency: 1000
};
this.gyroscope.getCurrent(options)
.then((orientation: GyroscopeOrientation) => {
this.orientation=orientation
console.log("orientation "+this.orientation.x)
})
.catch()
this.gyroscope.watch()
.subscribe((orientation: GyroscopeOrientation) => {
this.orientation=orientation
});
});
}
}
你能不能帮我