JavaScript/position.js
//Sets current heading as the difference between North and user heading.
Sets current heading as the difference between North and user heading.
Sets current heading as the difference between North and user heading .
function calculateHeading() {
    if (window.DeviceOrientationEvent) {
        window.addEventListener("deviceorientation", function (event) {
            if ('ondeviceorientationabsolute' in window) {
                window.ondeviceorientationabsolute = function(event) {
                    currHeading = event.alpha;
                    return true;
                };
            } else if(event.webkitCompassHeading) {
                var compass = event.webkitCompassHeading;
                handleOrientationEvent(compass);
                return true;
            } else if (event.absolute == true) {
                var compass = event.alpha;
                handleOrientationEvent(compass);
                return true;
            } else {
                demo.innerHTML = "<br>Compass Heading Not Working";
                return false;
            }
        }, true);
    } else {
        demo.innerHTML = "<br>Compass Heading Not Working";
        return false;
    }
}
function calculateHeading ( ) { if ( window . DeviceOrientationEvent ) { window . addEventListener ( "deviceorientation" , function ( event ) { if ( 'ondeviceorientationabsolute' in window ) { window . ondeviceorientationabsolute = function ( event ) { currHeading = event . alpha ; return true ; } ; } else if ( event . webkitCompassHeading ) { var compass = event . webkitCompassHeading ; handleOrientationEvent ( compass ) ; return true ; } else if ( event . absolute == true ) { var compass = event . alpha ; handleOrientationEvent ( compass ) ; return true ; } else { demo . innerHTML = "<br>Compass Heading Not Working" ; return false ; } } , true ) ; } else { demo . innerHTML = "<br>Compass Heading Not Working" ; return false ; } }
Sets current heading as the difference between North and user heading.
Sets current heading as the difference between North and user heading .