title: JS HTML Detect/Get Compass Heading for Android
body: <p>I'm building google maps based website and  I'm trying to integrate a compass (get mobile absolute heading), but the problem is that I'm getting an absolute heading only for iPhone, while android always gives me relative heading to the direction I loaded the page.</p>
  
  <p>How can I get android heading relative to the north? </p>
  
  <p>Here is my code now:</p>
  
  <pre><code>if (window.DeviceOrientationEvent &amp;&amp; mobile) {
      window.addEventListener('deviceorientation', function(event) {
          var dir;
          if (event.webkitCompassHeading) {
              // Apple works only with this, alpha doesn't work
              dir = event.webkitCompassHeading + 180; 
          } else { 
              //tried also event.alpha...
              dir = event.absolute;
          }
  
          var arrowPath = {
              path: 'M -50 120 L 50 120 L 000 170 z',
              fillColor: black,
              fillOpacity: 1,
              scale: 0.1,
              strokeOpacity: 0,
              strokeColor: 'white',
              strokeWeight: 1,
              rotation: dir
          };
  
          userDirection.setIcon(arrowPath);
      });
  }
  </code></pre>