Removed GyroNorm for compass use, updated styles
parent
9460e41bb7
commit
c14553940e
@ -1,39 +1,46 @@
|
||||
'use strict'
|
||||
/* global navigator $ */
|
||||
|
||||
|
||||
// Set units based on browser locale
|
||||
const metric = !(window.navigator.language=='en-US'||window.navigator.language=='my');
|
||||
const metric = !(window.navigator.language=='en-US'||window.navigator.language=='my')
|
||||
|
||||
// Track location
|
||||
if (!navigator.geolocation){ $('#no-gps').show(); }
|
||||
else { navigator.geolocation.watchPosition(
|
||||
|
||||
// Got location
|
||||
function(pos) {
|
||||
let lat = pos.coords.latitude.toFixed(4);
|
||||
let lon = pos.coords.longitude.toFixed(4);
|
||||
$('#lat').text((lat.substring(0,1)=='-')? lat.substring(1)+' S' : lat+' N');
|
||||
$('#lon').text((lon.substring(0,1)=='-')? lon.substring(1)+' E' : lon+' W');
|
||||
|
||||
// Get altitude
|
||||
if (pos.coords.altitude){
|
||||
var alt = (metric)? pos.coords.altitude.toFixed(1)+' m':(pos.coords.altitude*0.3048).toFixed(1)+' ft';
|
||||
$('#alt').show().text(alt);
|
||||
}
|
||||
else {
|
||||
$('#alt').hide();
|
||||
}
|
||||
},
|
||||
|
||||
// Got error
|
||||
function() {
|
||||
$('.coord').hide();
|
||||
$('#rotated').hide();
|
||||
$('#no-gps').show();
|
||||
},
|
||||
// Check for GPS capability
|
||||
if (!navigator.geolocation) $('#no-gps').show()
|
||||
|
||||
// Start tracking
|
||||
else navigator.geolocation.watchPosition(
|
||||
|
||||
// Options
|
||||
{ enableHighAccuracy:true }
|
||||
// Got location callback
|
||||
function(pos) {
|
||||
let lat = pos.coords.latitude.toFixed(4)
|
||||
let lon = pos.coords.longitude.toFixed(4)
|
||||
$('#lat').text(
|
||||
(lat.substring(0,1)=='-')? // Negative values are South
|
||||
lat.substring(1)+' S' : lat+' N'
|
||||
)
|
||||
$('#lon').text(
|
||||
(lon.substring(0,1)=='-')? // Negative values are East
|
||||
lon.substring(1)+' E' : lon+' W'
|
||||
)
|
||||
|
||||
);
|
||||
}
|
||||
// Get altitude
|
||||
if (pos.coords.altitude)
|
||||
$('#alt').show().text(
|
||||
(metric)? // Convert to feet if needed
|
||||
pos.coords.altitude.toFixed(1)+' m':
|
||||
(pos.coords.altitude*0.3048).toFixed(1)+' ft'
|
||||
)
|
||||
else $('#alt').hide()
|
||||
},
|
||||
|
||||
// Got error
|
||||
function() {
|
||||
$('.coord').hide()
|
||||
$('#no-gps').show()
|
||||
},
|
||||
|
||||
// Options
|
||||
{ enableHighAccuracy:true }
|
||||
|
||||
)
|
||||
|
@ -1,32 +1,21 @@
|
||||
'use strict'
|
||||
/* global $ GyroNorm */
|
||||
/* global $ window */
|
||||
|
||||
|
||||
// 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', function(e){
|
||||
|
||||
})
|
||||
// No orientation data
|
||||
if(!e) $('#no-dir').show()
|
||||
|
||||
})
|
||||
// Set orientation
|
||||
else {
|
||||
$('#no-dir').hide()
|
||||
const rot = 'rotate('+e.alpha.toString().substring(0,5)+'deg)'
|
||||
$('#rose').css({
|
||||
'-ms-transform': rot,
|
||||
'-webkit-transform': rot,
|
||||
'transform': rot
|
||||
})
|
||||
}
|
||||
|
||||
//window.addEventListener("deviceorientation", setRose, true)
|
||||
}, true)
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue