HTML5 get gyroscope, gravity sensor (forward)

Source: Internet
Author: User

The deviceorientationevent is the absolute value of obtaining the direction and obtaining the device at rest;
Devicemotionevent is the rate at which the device moves relative to the previous time

The device Locator API, which allows you to collect device orientation and mobile information. In addition, the API is used only on devices that have a gyroscope capability.

<title>DeviceOrientationEvent</title>
<meta charset= "UTF-8"/>

<body>
<p> around: <span id= "Alpha" >0</span>
</p>
<p> before and after: <span id= "Beta" >0</span>
</p>
<p> twist: <span id= "Gamma" >0</span>
</p>
<p> North Arrow Point: <span id= "heading" >0</span> degree </p>
<p> North Needle accuracy: <span id= "accuracy" >0</span> degree </p>
<p>x axis acceleration: <span id= "x" >0</span> meters per two square seconds </p>
<p>y axis acceleration: <span id= "y" >0</span> meters per two square seconds </p>
<p>z axis acceleration: <span id= "Z" >0</span> meters per two square seconds </p>
<p>x axis Acceleration (considering acceleration of gravity): <span id= "xg" >0</span> meters per two square seconds </p>
<p>y axis Acceleration (considering the acceleration of gravity): <span id= "YG" >0</span> meters per two square seconds </p>
<p>z axis Acceleration (considering acceleration of gravity): <span id= "ZG" >0</span> meters per two square seconds </p>
<p> rotation speed: <span id= "Ralpha" >0</span> degrees per second </p>
<p> before and after rotation speed: <span id= "Rbeta" >0</span> degrees per second </p>
<p> Twist Speed: <span id= "Rgamma" >0</span> degrees per second </p>
<p> last received notification interval: <span id= "Interval" >0</span> milliseconds </p>


<script type= "Text/javascript" >
function Orientationhandler (event) {
document.getElementById ("Alpha"). InnerHTML = Event.alpha;
document.getElementById ("beta"). InnerHTML = Event.beta;
document.getElementById ("Gamma"). InnerHTML = Event.gamma;
document.getElementById ("heading"). InnerHTML = event.webkitcompassheading;
document.getElementById ("accuracy"). InnerHTML = Event.webkitcompassaccuracy;

}


function Motionhandler (event) {
document.getElementById ("Interval"). InnerHTML = Event.interval;
var acc = event.acceleration;
document.getElementById ("x"). InnerHTML = acc.x;
document.getElementById ("Y"). InnerHTML = Acc.y;
document.getElementById ("Z"). InnerHTML = Acc.z;
var accgravity = event.accelerationincludinggravity;
document.getElementById ("xg"). InnerHTML = accgravity.x;
document.getElementById ("YG"). InnerHTML = ACCGRAVITY.Y;
document.getElementById ("ZG"). InnerHTML = accgravity.z;
var rotationrate = event.rotationrate;
document.getElementById ("Ralpha"). InnerHTML = Rotationrate.alpha;
document.getElementById ("Rbeta"). InnerHTML = Rotationrate.beta;
document.getElementById ("Rgamma"). InnerHTML = Rotationrate.gamma;
}

if (window. Devicemotionevent) {
Window.addeventlistener ("Devicemotion", Motionhandler, false);
} else {
Document.body.innerHTML = "What user agent u r using???";
}

if (window. Deviceorientationevent) {
Window.addeventlistener ("Deviceorientation", Orientationhandler, false);
} else {
Document.body.innerHTML = "What user agent u r using???";
};
</script>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.