Javascript 设备运动插件

Javascript 设备运动插件,javascript,html,accelerometer,Javascript,Html,Accelerometer,我正在做一个应用程序,它将使用加速计作为资源。我用HTML5和JavaScript编程,然后我测试了应用程序,它在不同的智能手机上给出了不同的值 我该如何解决这个问题 <script type="text/javascript" charset="utf-8"> // The watch id references the current `watchAcceleration` var watchID = null; // Wait for device API librari

我正在做一个应用程序,它将使用
加速计
作为资源。我用HTML5和JavaScript编程,然后我测试了应用程序,它在不同的智能手机上给出了不同的值

我该如何解决这个问题

 <script type="text/javascript" charset="utf-8">

// The watch id references the current `watchAcceleration`
var watchID = null;

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

// device APIs are available
//
function onDeviceReady() {
    startWatch();
}

// Start watching the acceleration
//
function startWatch() {

    // Update acceleration every 3 seconds
    var options = { frequency: 3000 };

    watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
}

// Stop watching the acceleration
//
function stopWatch() {
    if (watchID) {
        navigator.accelerometer.clearWatch(watchID);
        watchID = null;
    }
}

// onSuccess: Get a snapshot of the current acceleration
//
function onSuccess(acceleration) {
    var element = document.getElementById('accelerometer');
    element.innerHTML = 'Acceleration X: ' + acceleration.x         + '<br />' +
                        'Acceleration Y: ' + acceleration.y         + '<br />' +
                        'Acceleration Z: ' + acceleration.z         + '<br />' +
                        'Timestamp: '      + acceleration.timestamp + '<br />';
}

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

</script>

//watch id引用当前的“watch加速”`
var-watchID=null;
//等待加载设备API库
//
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
//设备API可用
//
函数ondevicerady(){
startWatch();
}
//开始观察加速度
//
函数startWatch(){
//每3秒更新一次加速度
var选项={频率:3000};
watchID=navigator.Accelerator.watchAcceleration(onSuccess、onError、options);
}
//不要再看加速度了
//
功能秒表(){
if(watchID){
navigator.Accelerator.clearWatch(watchID);
watchID=null;
}
}
//onSuccess:获取当前加速度的快照
//
成功时的功能(加速){
var元素=document.getElementById('Accelerator');
element.innerHTML='Acceleration X:'+Acceleration.X+'
'+ “加速度Y:”+加速度.Y+”
”+ “加速度Z:”+加速度.Z+”
”+ '时间戳:'+acceleration.Timestamp+'
'; } //OneError:无法获取加速度 // 函数onError(){ 警报('onError!'); }
您能否举例说明在不同智能手机上遇到的这些“不同值”?你测试了哪些智能手机?我在三星Galaxy S IV和索尼Xperia E上进行了测试。索尼Xperia E中的值是X:0 Y:0,07~0,15(不稳定)Z:2,45 Galaxy S IV中的值是:-0,53 Y:0,05~0,09(不稳定)Z:9.46智能手机放在一张平板上。我有一位老师也在Ios上进行了测试,给了他不同的值,但我不知道他用的是哪一种。