-
Notifications
You must be signed in to change notification settings - Fork 5
/
deviceorientation.html
69 lines (66 loc) · 1.82 KB
/
deviceorientation.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<html>
<head>
<title>DeviceOrientation Events Demo</title>
</head>
<body>
<h3>deviceorientation</h3>
<p id="deviceorientation"></p>
<h3>deviceorientationabsolute</h3>
<p id="deviceorientationabsolute"></p>
<h3>devicemotion</h3>
<p id="devicemotion"></p>
<script>
function onSuccess(position) {
console.log(position);
output.innerHTML = `
<pre>
latitude: ${position.coords.latitude}
longitude: ${position.coords.longitude}
altitude: ${position.coords.altitude}
accuracy: ${position.coords.accuracy}
altitudeAccuracy: ${position.coords.altitudeAccuracy}
heading: ${position.coords.heading}
speed: ${position.coords.speed}
timestamp: ${position.timestamp}
</pre>
`;
}
window.addEventListener('deviceorientation', (event) => {
document.getElementById('deviceorientation').innerHTML = `
<pre>
alpha: ${event.alpha}
beta: ${event.beta}
gamma: ${event.gamma}
absolute: ${event.absolute}
</pre>
`;
});
window.addEventListener('deviceorientationabsolute', (event) => {
document.getElementById('deviceorientationabsolute').innerHTML = `
<pre>
alpha: ${event.alpha}
beta: ${event.beta}
gamma: ${event.gamma}
absolute: ${event.absolute}
</pre>
`;
});
window.addEventListener('devicemotion', (event) => {
document.getElementById('devicemotion').innerHTML = `
<pre>
acceleration.x: ${event.acceleration.x}
acceleration.y: ${event.acceleration.y}
acceleration.z: ${event.acceleration.z}
accelerationIncludingGravity.x: ${event.accelerationIncludingGravity.x}
accelerationIncludingGravity.y: ${event.accelerationIncludingGravity.y}
accelerationIncludingGravity.z: ${event.accelerationIncludingGravity.z}
rotationRate.alpha: ${event.rotationRate.alpha}
rotationRate.beta: ${event.rotationRate.beta}
rotationRate.gamma: ${event.rotationRate.gamma}
interval: ${event.interval}
</pre>
`;
});
</script>
</body>
</html>