2018-08-30 12:01:11 -06:00
|
|
|
'use strict'
|
|
|
|
/* global navigator $ */
|
|
|
|
|
2018-08-30 12:52:14 -06:00
|
|
|
|
2017-03-29 06:02:16 -06:00
|
|
|
// Set units based on browser locale
|
2018-08-30 12:52:14 -06:00
|
|
|
const metric = !(window.navigator.language=='en-US'||window.navigator.language=='my')
|
2016-12-13 15:54:56 -07:00
|
|
|
|
2018-08-30 12:52:14 -06:00
|
|
|
// Check for GPS capability
|
|
|
|
if (!navigator.geolocation) $('#no-gps').show()
|
|
|
|
|
|
|
|
// Start tracking
|
|
|
|
else navigator.geolocation.watchPosition(
|
2017-03-29 06:02:16 -06:00
|
|
|
|
2018-10-03 18:30:08 -06:00
|
|
|
// Got location callbackw
|
2018-08-30 12:52:14 -06:00
|
|
|
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
|
2018-10-03 18:30:08 -06:00
|
|
|
lon.substring(1)+' W' : lon+' E'
|
2018-08-30 12:52:14 -06:00
|
|
|
)
|
2017-03-29 06:02:16 -06:00
|
|
|
|
2018-10-03 18:30:08 -06:00
|
|
|
// Get altitude
|
|
|
|
if (pos.coords.altitude) {
|
2018-08-30 12:52:14 -06:00
|
|
|
$('#alt').show().text(
|
|
|
|
(metric)? // Convert to feet if needed
|
|
|
|
pos.coords.altitude.toFixed(1)+' m':
|
2018-10-03 18:30:08 -06:00
|
|
|
(pos.coords.altitude*3.28084).toFixed(1)+' ft'
|
2018-08-30 12:52:14 -06:00
|
|
|
)
|
2018-10-03 18:30:08 -06:00
|
|
|
}
|
2018-08-30 12:52:14 -06:00
|
|
|
else $('#alt').hide()
|
|
|
|
},
|
|
|
|
|
|
|
|
// Got error
|
|
|
|
function() {
|
|
|
|
$('.coord').hide()
|
|
|
|
$('#no-gps').show()
|
|
|
|
},
|
|
|
|
|
|
|
|
// Options
|
|
|
|
{ enableHighAccuracy:true }
|
|
|
|
|
|
|
|
)
|