Javascript 离子/phonegap的compass插件中未定义的watchHeading
嗯,我在做一个爱奥尼亚的小项目。我正在使用ngCordova添加一些很酷的插件,比如compass的设备定位。但我不能强迫它工作。我已经安装了ngCordova并添加了插件(地理定位插件工作)。我不知道为什么这不管用 代码如下所示:Javascript 离子/phonegap的compass插件中未定义的watchHeading,javascript,cordova,ionic-framework,compass-geolocation,Javascript,Cordova,Ionic Framework,Compass Geolocation,嗯,我在做一个爱奥尼亚的小项目。我正在使用ngCordova添加一些很酷的插件,比如compass的设备定位。但我不能强迫它工作。我已经安装了ngCordova并添加了插件(地理定位插件工作)。我不知道为什么这不管用 代码如下所示: .controller('GeoLocationCtrl', function($scope, $cordovaGeolocation, $cordovaDeviceOrientation, $ionicPlatform, $document) { $scope.l
.controller('GeoLocationCtrl', function($scope, $cordovaGeolocation, $cordovaDeviceOrientation, $ionicPlatform, $document) {
$scope.lat = 0;
$scope.long = 0;
$scope.position = {};
$ionicPlatform.ready(function() {
var options = {frequency: 1000}; // Update every 1 second
var watch2 = $cordovaDeviceOrientation.watchHeading(options); ///LINE 53!
watch2.promise.then(function (result) { /* unused */
},
function (err) {
// An error occurred
}, function (position) {
// Heading comes back in
// position.magneticHeading
$scope.position = position.magneticHeading;
});
$cordovaDeviceOrientation.clearWatch(watch2.watchId)
.then(function (result) {
// Success!
}, function (err) {
// An error occurred
});
});
})
但我得到的只是:
ripple.js:37
TypeError: Cannot read property 'watchHeading' of undefined
at Object.watchHeading (http://localhost:8080/lib/ngCordova/dist/ng- cordova.min.js:1:14565)
at http://localhost:8080/js/controllers.js:53:44
at http://localhost:8080/lib/ionic/js/ionic.bundle.js:37388:19
at Object.ionic.Platform.ready (http://localhost:8080/lib/ionic/js/ionic.bundle.js:1915:9)
at Object.self.ready (http://localhost:8080/lib/ionic/js/ionic.bundle.js:37386:26)
at new <anonymous> (http://localhost:8080/js/controllers.js:15:20)
at invoke (http://localhost:8080/lib/ionic/js/ionic.bundle.js:11591:17)
at Object.instantiate (http://localhost:8080/lib/ionic/js/ionic.bundle.js:11602:23)
at http://localhost:8080/lib/ionic/js/ionic.bundle.js:14906:28
at updateView (http://localhost:8080/lib/ionic/js/ionic.bundle.js:42986:30) ionic.bundle.js:17696
ripple.js:37
TypeError:无法读取未定义的属性“watchHeading”
在Object.watchHeading(http://localhost:8080/lib/ngCordova/dist/ng-cordova.min.js:1:14565)
在http://localhost:8080/js/controllers.js:53:44
在http://localhost:8080/lib/ionic/js/ionic.bundle.js:37388:19
在Object.ionic.Platform.ready(http://localhost:8080/lib/ionic/js/ionic.bundle.js:1915:9)
准备好了(http://localhost:8080/lib/ionic/js/ionic.bundle.js:37386:26)
在纽约(http://localhost:8080/js/controllers.js:15:20)
在调用时(http://localhost:8080/lib/ionic/js/ionic.bundle.js:11591:17)
在Object.instantiate(http://localhost:8080/lib/ionic/js/ionic.bundle.js:11602:23)
在http://localhost:8080/lib/ionic/js/ionic.bundle.js:14906:28
在updateView(http://localhost:8080/lib/ionic/js/ionic.bundle.js:42986:30)爱奥尼亚.邦德.js:17696
谢谢你的帮助 你把插件添加到你的项目中了吗?i、 e.
cordova插件添加org.apache.cordova.device-orientation
对不起,我想我弄乱了描述。。。但是,是的,我以这种方式添加了这个插件。它是在项目源代码中添加的,所以我猜它安装正确。好吧,当我在cordovaDeviceOrientation.watchHeading(选项)上添加console.log时,它也会返回object。所以我几乎可以肯定插件安装得很好