Removed GyroNorm for compass use, updated styles
parent
9460e41bb7
commit
c14553940e
|
@ -1,39 +1,46 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
/* global navigator $ */
|
/* global navigator $ */
|
||||||
|
|
||||||
// Set units based on browser locale
|
|
||||||
const metric = !(window.navigator.language=='en-US'||window.navigator.language=='my');
|
|
||||||
|
|
||||||
// Track location
|
// Set units based on browser locale
|
||||||
if (!navigator.geolocation){ $('#no-gps').show(); }
|
const metric = !(window.navigator.language=='en-US'||window.navigator.language=='my')
|
||||||
else { navigator.geolocation.watchPosition(
|
|
||||||
|
// Check for GPS capability
|
||||||
|
if (!navigator.geolocation) $('#no-gps').show()
|
||||||
|
|
||||||
|
// Start tracking
|
||||||
|
else navigator.geolocation.watchPosition(
|
||||||
|
|
||||||
// Got location
|
// Got location callback
|
||||||
function(pos) {
|
function(pos) {
|
||||||
let lat = pos.coords.latitude.toFixed(4);
|
let lat = pos.coords.latitude.toFixed(4)
|
||||||
let lon = pos.coords.longitude.toFixed(4);
|
let lon = pos.coords.longitude.toFixed(4)
|
||||||
$('#lat').text((lat.substring(0,1)=='-')? lat.substring(1)+' S' : lat+' N');
|
$('#lat').text(
|
||||||
$('#lon').text((lon.substring(0,1)=='-')? lon.substring(1)+' E' : lon+' W');
|
(lat.substring(0,1)=='-')? // Negative values are South
|
||||||
|
lat.substring(1)+' S' : lat+' N'
|
||||||
// Get altitude
|
)
|
||||||
if (pos.coords.altitude){
|
$('#lon').text(
|
||||||
var alt = (metric)? pos.coords.altitude.toFixed(1)+' m':(pos.coords.altitude*0.3048).toFixed(1)+' ft';
|
(lon.substring(0,1)=='-')? // Negative values are East
|
||||||
$('#alt').show().text(alt);
|
lon.substring(1)+' E' : lon+' W'
|
||||||
}
|
)
|
||||||
else {
|
|
||||||
$('#alt').hide();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// Got error
|
// Get altitude
|
||||||
function() {
|
if (pos.coords.altitude)
|
||||||
$('.coord').hide();
|
$('#alt').show().text(
|
||||||
$('#rotated').hide();
|
(metric)? // Convert to feet if needed
|
||||||
$('#no-gps').show();
|
pos.coords.altitude.toFixed(1)+' m':
|
||||||
},
|
(pos.coords.altitude*0.3048).toFixed(1)+' ft'
|
||||||
|
)
|
||||||
// Options
|
else $('#alt').hide()
|
||||||
{ enableHighAccuracy:true }
|
},
|
||||||
|
|
||||||
);
|
// Got error
|
||||||
}
|
function() {
|
||||||
|
$('.coord').hide()
|
||||||
|
$('#no-gps').show()
|
||||||
|
},
|
||||||
|
|
||||||
|
// Options
|
||||||
|
{ enableHighAccuracy:true }
|
||||||
|
|
||||||
|
)
|
||||||
|
|
41
direction.js
41
direction.js
|
@ -1,32 +1,21 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
/* global $ GyroNorm */
|
/* global $ window */
|
||||||
|
|
||||||
|
|
||||||
// Set compass orientation
|
window.addEventListener('deviceorientation', function(e){
|
||||||
var gn = new GyroNorm()
|
|
||||||
|
|
||||||
gn.init().then(function(){
|
|
||||||
gn.start(function(data){
|
|
||||||
|
|
||||||
console.log(data.do.alpha)
|
// No orientation data
|
||||||
// No orientation data
|
if(!e) $('#no-dir').show()
|
||||||
// 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
|
|
||||||
})
|
|
||||||
// }
|
|
||||||
|
|
||||||
})
|
// 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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
})
|
}, true)
|
||||||
|
|
||||||
//window.addEventListener("deviceorientation", setRose, true)
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
10
index.html
10
index.html
|
@ -47,9 +47,9 @@
|
||||||
<header>
|
<header>
|
||||||
|
|
||||||
<div class='error' id='no-gps'>No GPS data available. </div>
|
<div class='error' id='no-gps'>No GPS data available. </div>
|
||||||
<div class='coord' id='lat'>0.00000 N</div>
|
<div class='coord' id='lat'>0.0000 N</div>
|
||||||
<div class='coord' id='lon'>0.00000 E</div>
|
<div class='coord' id='lon'>0.0000 W</div>
|
||||||
<div class='error' id='no-alt'>No altitude data available. </div>
|
|
||||||
<div class='coord' id='alt'></div>
|
<div class='coord' id='alt'></div>
|
||||||
|
|
||||||
</header>
|
</header>
|
||||||
|
@ -58,7 +58,6 @@
|
||||||
|
|
||||||
<noscript>You need javascript to use this. </noscript>
|
<noscript>You need javascript to use this. </noscript>
|
||||||
<div class='error' id='no-dir'>No direction available. Try this on a smartphone with an internal compass.</div>
|
<div class='error' id='no-dir'>No direction available. Try this on a smartphone with an internal compass.</div>
|
||||||
<div class='error' id='rotated'>Note: the compass may be 90° off when used in landscape mode.</div>
|
|
||||||
|
|
||||||
<img id='rose' src="rose.svg">
|
<img id='rose' src="rose.svg">
|
||||||
|
|
||||||
|
@ -66,10 +65,9 @@
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
<div id='about'><a href="https://github.com/keith24/Compass/blob/master/README.md">About</a></div>
|
<div id='about'><a href="https://github.com/keith24/Compass/blob/master/README.md">About</a></div>
|
||||||
<div id='by'>by <a href="https://keithirwin.us/">Keith Irwin</a></div>
|
<div id='by'>by <a href="https://www.keithirwin.us/">Keith Irwin</a></div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<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="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
|
||||||
<script src="coordinates.js"></script>
|
<script src="coordinates.js"></script>
|
||||||
<script src="direction.js"></script>
|
<script src="direction.js"></script>
|
||||||
|
|
Loading…
Reference in New Issue