Note that there are some explanatory texts on larger screens.

plurals
  1. PONormalize deviceorientation data
    primarykey
    data
    text
    <p>I'm playing with deviceorientation in JavaScript and I noticed some differences between my Ipad (iOS 6.1) and my Nexus7 (Android 4.2.2).</p> <p>This code does not print the same data with the Ipad and the Nexus7.</p> <pre><code>&lt;html&gt; &lt;head/&gt; &lt;body&gt; &lt;button id="calibrate"&gt;Calibrate&lt;/button&gt; &lt;button id="stop"&gt;Stop&lt;/button&gt; &lt;button id="play"&gt;Play&lt;/button&gt; &lt;div id="log"&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt; &lt;script&gt; var log = document.getElementById('log'); var calibrate = false; var calibrateG = 0, calibrateB = 0, calibrateA = 0; var deviceorientation = function(e) { if (calibrate) { calibrateG = e.gamma; calibrateB = e.beta; calibrateA = e.alpha; calibrate = false; } var gamma = parseInt(e.gamma - calibrateG); var beta = parseInt(e.beta - calibrateB); var alpha = parseInt(e.alpha - calibrateA); var p = document.createElement('p'); p.innerHTML = gamma + ' ' + beta + ' ' + alpha; log.insertBefore(p, log.firstChild); } document.getElementById('stop').onclick = function() { window.removeEventListener('deviceorientation', deviceorientation); }; document.getElementById('play').onclick = function() { window.addEventListener('deviceorientation', deviceorientation); }; document.getElementById('calibrate').onclick = function() { calibrate = true; }; window.addEventListener('deviceorientation', deviceorientation); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>At start Android print 0 0 270 and iOS 0 0 0.</p> <p>Then when I move both in the same way, they don't print the same values.</p> <p>Can someone explain why, and if there are a way to normalize the data.</p> <p>UPDATE #1</p> <p>I already try some calibrations and I care about landscape/portrait. To reproduce, you can take the code above, put ipad and nexus7 in portrait in front of you. Calibrate the value of both (first button). Then take the right corner of the tablet and rotate it until the tablet reaches 90 degrees. The tablet should be on the left side.</p> <p>On Android the gamma goes from 0 to -80 and then jump to 270. On IOS the gamma goes from 0 to -180 without any jump.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload