{"id":1,"date":"2010-11-25T16:55:47","date_gmt":"2010-11-25T16:55:47","guid":{"rendered":"http:\/\/www.albertosarullo.com\/blog\/?p=1"},"modified":"2016-08-21T21:17:27","modified_gmt":"2016-08-21T21:17:27","slug":"javascript-accelerometer-demo-source","status":"publish","type":"post","link":"http:\/\/www.albertosarullo.com\/blog\/javascript-accelerometer-demo-source","title":{"rendered":"Javascript Accelerometer Demo and Source"},"content":{"rendered":"<p>IOS 4.2 (with new Safari Mobile) has the possibility to read sensor data like accelerometer and gyroscope directly from Javascript.<br \/>\n<!--more--><\/p>\n<h2>New Javascript objects and event handler<\/h2>\n<p>From javascript point of view, we have:<\/p>\n<ul>\n<li>new handler <strong>window.ondevicemotion<\/strong><\/li>\n<li>new event object:\n<ul>\n<li><strong>event.accelerationGravity<\/strong>, with x, y, z attributes<\/li>\n<li><strong>event.accelerationIncludingGravity<\/strong>, with x, y, z attributes<\/li>\n<li><strong>event.rotationRate<\/strong>, with alpha, beta, gamma attributes<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Code Snip<\/h2>\n<pre class=\"javascript\">window.ondevicemotion = function(event) {\r\n\tvar accelerationX = event.accelerationIncludingGravity.x;\r\n\tvar accelerationY = event.accelerationIncludingGravity.y;\r\n\tvar accelerationZ = event.accelerationIncludingGravity.z;\r\n}<\/pre>\n<h2>Demo<\/h2>\n<p><a href=\"\/demos\/accelerometer\/\">Online Demo (require Safari Mobile)<\/a><\/p>\n<h2>API<\/h2>\n<p><a href=\"https:\/\/developer.apple.com\/library\/ios\/documentation\/SafariDOMAdditions\/Reference\/DeviceMotionEventClassRef\/#\/\/apple_ref\/javascript\/instp\/DeviceMotionEvent\/acceleration\">DeviceMotionEvent Class<\/a><br \/>\n<a href=\"https:\/\/developer.apple.com\/library\/ios\/documentation\/SafariDOMAdditions\/Reference\/DeviceOrientationEventClassRef\/\">DeviceOrientationEvent Class<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>IOS 4.2 (with new Safari Mobile) has the possibility to read sensor data like accelerometer and gyroscope directly from Javascript.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,16,3],"tags":[5,6,4,7,8],"class_list":["post-1","post","type-post","status-publish","format-standard","hentry","category-ipad","category-iphone","category-javascript","tag-accelerometer","tag-gyro","tag-javascript-2","tag-mobile","tag-safari"],"_links":{"self":[{"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/comments?post=1"}],"version-history":[{"count":0,"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/posts\/1\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/media?parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/categories?post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.albertosarullo.com\/blog\/wp-json\/wp\/v2\/tags?post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}