加速

含まれています Accelerometer で特定の時点でキャプチャしたデータ。

プロパティ

  • x: x 軸の加速度の量です。(m/s ^2)(数)
  • y: y 軸の加速度の量です。(m/s ^2)(数)
  • z: z 軸の加速度の量です。(m/s ^2)(数)
  • タイムスタンプ: 作成時のタイムスタンプ (ミリ秒単位)。(,)

説明

Accelerationオブジェクトの作成し、API のいずれかによって返される Accelerometer 方法。 加速度値のとおり重力の効果 (9.81 m/s ^2) デバイスにあるフラットとx y、直面していると返されるz値をする必要がありますように、 9.81.

サポートされているプラットフォーム

  • アンドロイド
  • ブラックベリー WebWorks (OS 5.0 およびより高い)
  • iOS
  • Tizen
  • Windows Phone 7 と 8
  • Windows 8

簡単な例

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!');
};

navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);

完全な例

<!DOCTYPE html>
<html>
  <head>
    <title>Acceleration Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for device API libraries to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // device APIs are available
    //
    function onDeviceReady() {
        navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);
    }

    // onSuccess: Get a snapshot of the current acceleration
    //
    function onSuccess(acceleration) {
        alert('Acceleration X: ' + acceleration.x + '\n' +
              'Acceleration Y: ' + acceleration.y + '\n' +
              'Acceleration Z: ' + acceleration.z + '\n' +
              'Timestamp: '      + acceleration.timestamp + '\n');
    }

    // onError: Failed to get the acceleration
    //
    function onError() {
        alert('onError!');
    }

    </script>
  </head>
  <body>
    <h1>Example</h1>
    <p>getCurrentAcceleration</p>
  </body>
</html>