cordova插件-Device Motion

2018-03-30 14:56:17 浏览数 (2)

  • 添加插件

$ cordova plugin addcordova-plugin-device-motion

图 12如上则插入成功

  • 插件的使用
  • Methods
  • navigator.accelerometer.getCurrentAcceleration
  • navigator.accelerometer.watchAcceleration
  • navigator.accelerometer.clearWatch

2. Example

代码语言:javascript复制
var watchID;
function  getCurrentAcceleration() {
    navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);
}

function watchACC() {
    var options = { frequency: 3000 };  // Update every 3 seconds

    watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
}
function clearWa() {
    navigator.accelerometer.clearWatch(watchID);

}
function onSuccess(acceleration) {
    alert('Acceleration X: '   acceleration.x   'n'  
            'Acceleration Y: '   acceleration.y   'n'  
            'Acceleration Z: '   acceleration.z   'n'  
            'Timestamp: '        acceleration.timestamp   'n');
}

function onError() {
    alert('onError!');
}

0 人点赞