【发布时间】:2013-12-08 03:37:37
【问题描述】:
所以我目前有一个 JavaScript 代码,我在我的 iPhone 上运行它来提取它的加速度计数据。我想做的是将这些数据传递给我的 Mac Book Pro。变量每秒会更改多次,所以我正在考虑使用 Socket.io,有人知道我会怎么做吗?我将非常感谢我能得到的任何帮助。谢谢。
<html>
<body>
<div id="content">
<h1>Accelerometer JavaScript Test</h1>
<ul>
<li>acceleration x: <span id="accelerationX"></span></li>
<li>acceleration y: <span id="accelerationY"></span></li>
<li>Motor Speed: <span id="speed"></span></li>
</ul>
</div>
<script type="text/javascript">
window.ondevicemotion = function(e){
var x = e.accelerationIncludingGravity.x;
var y = e.accelerationIncludingGravity.y;
var newx = x * 100
var newy = y * 100
var finalx = Math.round(x);
var finaly = Math.round(y);
document.getElementById("accelerationX").innerHTML = finalx
document.getElementById("accelerationY").innerHTML = finaly
speed = finalx * 10
document.getElementById("speed").innerHTML = speed
}
</script>
</body>
</html>
【问题讨论】:
标签: javascript ios