大家好我有一个JavaScript功能来加速。我想通过加速来获得速度。
有人可以帮帮我吗?没有方法可以在API中获得 speed 。function getDataFromSensor() {
//call js.call to get data FROM accelerometer
var rtrn = js.call('api.sensors.getAccelerometer()', {});
// parse JSONObject
var obj = JSON.parse(rtrn);
//get value of axe x
var x = obj.accelerometerX;
//get value of axe y
var y = obj.accelerometerY;
//get value of axe z
var z = obj.accelerometerZ;
// use gravity according to your place in this example I Choose 9
var result = (x * x + y * y + z * z) / (9 * 9);
//If mobile move any direction then the following condition will become true
if (result > 2) {
//Generate random number between 0 and 1 every time and display on text view
js.setProperty('menu.Text_1', 'text', "err");
} else {
js.setProperty('menu.Text_1', 'text', "result:" + result);
}
}