이 아닌 문서의 최신 버전입니다!
Click here for the latest released version.
accelerometer.getCurrentAcceleration
X, y및 z 축 따라 현재 가속도 얻을.
navigator.accelerometer.getCurrentAcceleration(accelerometerSuccess, accelerometerError);
설명
가 속도계 3 차원 x, y및 z 축 따라 현재 장치 방향 기준으로 이동 (델타) 변경 내용을 감지 하는 모션 센서입니다.
이 가속도 값에 반환 되는 [accelerometerSuccess](parameters/accelerometerSuccess.html)
콜백 함수.
지원 되는 플랫폼
- 안 드 로이드
- 블랙베리 WebWorks (운영 체제 5.0와 더 높은)
- iOS
- Tizen
- Windows Phone 7과 8
- 윈도우 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>
iOS 단점
iOS는 어떤 주어진된 시점에서 현재 가속도의 개념을 인식 하지 못합니다.
가속을 감시 하며 데이터 캡처에 주어진 시간 간격.
따라서,는
getCurrentAcceleration
에서 보고 된 마지막 값을 생성 하는 함수는watchAccelerometer
전화.