- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
首先我要说的是,我看到了很多这样的问题,其中很多只是说出来<script src="cordova-x-x-x.js"></script>
有人说不要将 cordova.js 文件包含到 Phonegap Build 中。
所以我已经测试和修复我的代码一段时间了,但仍然收到来自 onError function
的错误。 .我还复制并粘贴了 phonegap docs 中的代码.
所以这是来自 url 的干净代码:
<!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">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);
}
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!');
}
</script>
</head>
<body>
</body>
</html>
并且在我的 config.xml 文件中添加了:
<gap:plugin name="org.apache.cordova.device-motion" />
<gap:plugin name="org.apache.cordova.device-orientation" />
最佳答案
在测试并询问 Phonegap Build 团队后,他们向我展示了包含所有功能的代码。这是让加速度计与 Phonegap Build 一起工作的最佳方式
<!DOCTYPE html>
<html>
<head>
<title>Device Ready Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
alert("Device is Ready");
alert(device.available);
}
function getAcceleration(){
navigator.accelerometer.getCurrentAcceleration(onAccelSuccess, onError);
}
function onAccelSuccess(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 />';
}
function onError() {
alert('onError!');
}
function startWatch() {
// Update acceleration every 1 seconds
var options = { frequency: 1000 };
watchID = navigator.accelerometer.watchAcceleration(onAccelSuccess, onError, options);
}
function stopWatch() {
if (watchID) {
navigator.accelerometer.clearWatch(watchID);
watchID = null;
}
}
</script>
</head>
<body onload="onLoad()">
<p>
<button onclick="getAcceleration()">Get Acceleration</button>
</p>
<p>
<button onclick="startWatch()">Watch Acceleration</button>
</p>
<p>
<button onclick="stopWatch()">Stop Watching Acceleration</button>
</p>
<div id="accelerometer">Waiting for accelerometer...</div>
</body>
</html>
关于android - Phonegap 版本 : accelerometer not working android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25282405/
我有一个加速度计和磁力计,每个都产生原始 X、Y 和 Z 读数。由此我需要确定一个物体的磁航向。 我不太擅长三角,但我整理了一个公式,该公式确实对设备的旋转做出了很好的 react ,但也对人们认为不
我对 ADXL345 数字加速度计中的寄存器感到困惑。 让我感到困惑的第一件事是我必须写入数据以设置 +/-2g 的分辨率。我在数据表中没有发现任何提及该寄存器的内容。 其次,有两个寄存器用于存储 X
我想知道如何计算使用加速度计采取的步骤。实际上我计算加速度并使用此代码来计算步数 length = sqrt(x * x + y * y + z * z); if(length>=2){ ste
我想知道是否有一些库/算法/技术可以帮助从加速度计数据(从任何智能手机中提取)中提取用户上下文(步行/站立)? 例如,我会在一定的时间段内每 5 秒收集一次加速度计数据,然后识别用户上下文(例如,前
我正在使用 IMU(3 轴加速度计、3 轴陀螺仪、3 轴磁力计),我想从加速度计数据中获取线性加速度。我了解传感器融合以及使用陀螺仪数据(并获取方向)获取重力矢量的能力,从而消除其对相应轴的影响。 我
我有一个xyz加速度计和磁力计。现在,我想同时使用这两种方法来确定设备的方向。我看到的问题是,根据设备的方向,我需要以不同的顺序使用传感器。 让我举个例子。如果我的设备正对我,则可以使用加速度计确定侧
在许多论坛上阅读了许多研究和论文后,关于如何基于加速度数据测量距离 我找到了双重积分方法,但是与此方法相关的误差很大,并且会随着时间而增加。 另外,我发现有人建议卡尔曼滤波器,我阅读了一些有关它的引用
加速度计具有三个值:x、y、z。 让我们想象一个 Racket 有一个加速度计。如果我把 Racket 正面朝上,我就知道x、y和z的方向在哪里。但是,如果我翻转 Racket 并将其倒置。 x、y、
我已经搜索了几个小时,但仍然没有找到我的问题的明确答案。 场景是这样的:用户尽可能高地扔 iPhone,我想测量 iPhone 的高度。 我想将加速度计与 Core Motion 一起使用,并且我成功
我有一辆小型遥控车在房间地板上行驶。为简单起见,让我们假设它沿 x 轴移动。现在,地板看起来很平坦,但每个表面都有非常细微的凹凸不平。因此,每当汽车不完全平坦时(就像在起始位置一样),或者换句话说,只
IOS5的发行版具有此核心功能listed as deprecated。有谁知道它将取代什么?我假设苹果不会从iPhone 5移除加速度计。 最佳答案 我尚未使用iOS 5,但已经在4.x中将UIAc
我有一个 3 轴加速度计(任何手机),但我找不到任何好的公式来解释来自它的数据。无论我做什么, Action 都是生涩/ NumPy 的。我读到我还需要欧拉角或旋转矩阵? 我将不胜感激任何阅读的好 M
我正在使用此设备 ( http://www.sparkfun.com/products/10724 ) 并基于此 http://www.x-io.co.uk/node/8#open_source_im
我有 MPU9250 IMU,我正在使用它从传感器输出数据中获取方向。在探索 MPU9250(还有其他传感器,如 BNO055)数据表时,我发现了加速度计和陀螺仪的满量程范围,如 ±2 ±4 ±8 ±
我正在尝试实现 Madgwick 传感器融合算法 from here在 STM Cortex M3 微 Controller 上的 LSM9DS0 传感器(加速度计、陀螺仪和磁力计)上。 所有传感器的
我可以通过手机向配对的 Microsoft Band 发送消息和/或对话,但我希望从 Band 向手机返回确认信息。由于似乎没有其他方法,我想我必须采取一个手势,例如用户来回旋转手腕一次,或者可能摇动
我正在使用 CMMotionManager 和 HKWorkoutSession 开发 Apple Watch 应用程序以获取加速度计和心率数据。该应用程序在短时间内(70 秒)运行良好,但当屏幕关闭
我想为慢跑者开发一个应用程序来计算那里的距离和速度。 通过搜索,我了解到 gps 或加速度计有两件事,加速度计比 GPS 使用起来更便宜。 我是 android 新手,我该如何继续? 最佳答案 我不知
我正在做这个应用程序,它的工作原理类似于计步器,但我希望它显示每一步的方向。 我正在做的是注册两个事件监听器,而不是针对每个 onsensorchanged 事件,我正在获取 sensor.TYPE_
是否可以将加速度计更新频率减慢到 1hz 以及如何? 我已经在 nexus 7 选项卡上尝试过:将 sensorDelay_Normal 更改为 1.000.000 但没有任何改变。谢谢! 代码如下:
我是一名优秀的程序员,十分优秀!