离子:无法读取未定义的 属性 'getCurrentAcceleration'

Ionic : Cannot read property 'getCurrentAcceleration' of undefined

我无法从 Ionic Framework 上的加速度计获取值,下面是代码,

执行代码出现错误:

Cannot read property 'getCurrentAcceleration' of undefined

.controller('DashCtrl', function($cordovaDeviceMotion) {

    $cordovaDeviceMotion.getCurrentAcceleration().then(function(result) {
      var X = result.x;
      var Y = result.y;
      var Z = result.z;
      var timeStamp = result.timestamp;
      console.log(result);
    }, function(err) {
        console.log(err);
      // An error occurred. Show a message to the user
    });


  // watch Acceleration
  var options = { frequency: 20000 };

    var watch = $cordovaDeviceMotion.watchAcceleration(options);
    watch.then(
      null,
      function(error) {
      // An error occurred
      },
      function(result) {
        var X = result.x;
        var Y = result.y;
        var Z = result.z;
        var timeStamp = result.timestamp;
    });


    watch.clearWatch();
    // OR
    $cordovaDeviceMotion.clearWatch(watch)
      .then(function(result) {
          console.log(result);
        // success
        }, function (error) {
        // error
      });
})

更多信息:

  1. 我从 http://ngcordova.com/docs/plugins/deviceMotion/
  2. 那里得到了代码
  3. 当我打印 $cordovaDeviceMotion 时,我得到的是空{}对象
  4. 在 GitHub 上创建问题:https://github.com/driftyco/ng-cordova/issues/1207

$cordovaDeviceMotion 在浏览器上不起作用,但在我的 android 欺骗上起作用。我们无法在浏览器上进行测试。

ngCordova:现在设备动作在浏览器上不起作用,但在设备(应用程序)中起作用 Apache Cordova:在浏览器和应用程序上工作。

所以,我在 GitHub

上提出了这个问题