From 527caa8ae5f274833eeef148477c8b512e536179 Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Thu, 30 Aug 2018 18:01:11 +0000 Subject: [PATCH] Fixed compass gyro at last --- script.js => coordinates.js | 36 +++++------------------------------- direction.js | 34 ++++++++++++++++++++++++++++++++++ index.html | 3 ++- 3 files changed, 41 insertions(+), 32 deletions(-) rename script.js => coordinates.js (61%) create mode 100644 direction.js diff --git a/script.js b/coordinates.js similarity index 61% rename from script.js rename to coordinates.js index 716eac6..2a17a0b 100755 --- a/script.js +++ b/coordinates.js @@ -1,10 +1,12 @@ -'use strict'; -/* global navigator $ GyroNorm */ +'use strict' +/* global navigator $ */ + +alert('coordinates loaded') // Set units based on browser locale const metric = !(window.navigator.language=='en-US'||window.navigator.language=='my'); -// Track GPS location +// Track location if (!navigator.geolocation){ $('#no-gps').show(); } else { navigator.geolocation.watchPosition( @@ -37,31 +39,3 @@ else { navigator.geolocation.watchPosition( ); } - -// Set compass orientation -var gn = new GyroNorm() - -gn.init().then(function(){ - gn.start(function(data){ - - // No orientation data - if (!data.do.absolute) { - $('#rotated').hide(); - $('#no-dir').show(); - } - - // Set orientation - else { - const rot = 'rotate('+data.do.alpha.toString().substring(0,5)+'deg)'; - $('#rose').css({ - '-ms-transform': rot, - '-webkit-transform': rot, - 'transform': rot - }) - } - - }) - -}) - -window.addEventListener("deviceorientation", setRose, true); \ No newline at end of file diff --git a/direction.js b/direction.js new file mode 100644 index 0000000..bce5d92 --- /dev/null +++ b/direction.js @@ -0,0 +1,34 @@ +'use strict' +/* global $ GyroNorm */ + +alert('direction loaded') + + +// Set compass orientation +var gn = new GyroNorm() + +gn.init().then(function(){ + gn.start(function(data){ + + console.log(data.do.alpha) + // No orientation data + // if (!data.do.absolute) { + // $('#rotated').hide() + // $('#no-dir').show() + // } + + // Set orientation + // else { + const rot = 'rotate('+data.do.alpha.toString().substring(0,5)+'deg)' + $('#rose').css({ + '-ms-transform': rot, + '-webkit-transform': rot, + 'transform': rot + }) + // } + + }) + +}) + +//window.addEventListener("deviceorientation", setRose, true) diff --git a/index.html b/index.html index 0e22e24..175c899 100755 --- a/index.html +++ b/index.html @@ -71,7 +71,8 @@ - + +