Fixed compass gyro at last
parent
98cba6ad7e
commit
527caa8ae5
|
@ -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);
|
|
@ -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)
|
|
@ -71,7 +71,8 @@
|
|||
|
||||
<script src="gyronorm.complete.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
|
||||
<script src="script.js"></script>
|
||||
<script src="coordinates.js"></script>
|
||||
<script src="direction.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
|
|
Loading…
Reference in New Issue