Merge branch 'develop'
commit
be7db6f3c1
22
index.html
22
index.html
|
@ -1,28 +1,14 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Spedometer</title>
|
<title>Spedometer</title>
|
||||||
|
<link type="text/css" rel="stylesheet" href="style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div id="speedometer">
|
<div id="speed">0.0</div>
|
||||||
<span id="speed"></span>
|
<div id="units">m.p.h.</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<script type="application/javascript">
|
<script type="application/javascript" src="main.js"></script>
|
||||||
const speedometer = document.getElementById('speedometer')
|
|
||||||
const speedSpan = document.getElementById('speed')
|
|
||||||
// Check for API
|
|
||||||
if (!'geolocation' in navigator) {
|
|
||||||
alert('No geolocation API available')
|
|
||||||
speedometer.innerHTML = 'No API'
|
|
||||||
} else {
|
|
||||||
const WID = navigator.geolocation.watchPosition( function(loc) {
|
|
||||||
console.log(JSON.stringify(loc.coords.speed))
|
|
||||||
//alert('speed:',loc.coords.speed)
|
|
||||||
if (loc.coords.speed) speedSpan.innerHTML = loc.coords.speed
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const speedDiv = document.getElementById('speed')
|
||||||
|
|
||||||
|
// Check for API
|
||||||
|
if (!'geolocation' in navigator) {
|
||||||
|
alert('No geolocation API available')
|
||||||
|
speedDiv.innerHTML = 'No API'
|
||||||
|
} else {
|
||||||
|
|
||||||
|
const WID = navigator.geolocation.watchPosition( function (loc) {
|
||||||
|
// got speed
|
||||||
|
if (loc.coords.speed) {
|
||||||
|
// convert to mph and display
|
||||||
|
speedDiv.innerHTML = (2.23693629205*loc.coords.speed).toFixed(1)
|
||||||
|
} else {
|
||||||
|
speedDiv.innerHTML = '0.0'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue