-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
79 lines (64 loc) · 1.78 KB
/
Copy pathindex.html
File metadata and controls
79 lines (64 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html lang="en">
<head>
<title>Geo</title>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
var timerStart, timerInterval;
var mps_to_mph = 2.2369362920544;
var average;
var options = {
timeout:10000,
enableHighAccuracy: true,
frequency: 5000
};
function showLocation(position) {
var timerNow = new Date().getTime();
var elapsedInterval = timerNow - timerInterval;
var elapsedStart = timerNow - timerStart;
var speed = position.coords.speed;
average += speed * elapsedInterval;
$('#current').html(speed * mps_to_mph);
$('#average').html((average / elapsedStart) * mps_to_mph);
$('#elapsedInterval').html(elapsedInterval);
$('#elapsedStart').html(elapsedStart);
timerInterval = timerNow;
}
function errorHandler(err) {
if (err.code == 1) {
$('#test').html('Error: Access is denied!');
} else if (err.code == 2) {
$('#test').html('Error: Position is unavailable!');
}
}
function getLocationUpdate() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(showLocation, errorHandler, options);
} else {
$('#test').html('Sorry, browser does not support geolocation!');
}
}
$(document).ready(function() {
$('#start').click(function() {
timerStart = new Date().getTime();
timerInterval = timerStart;
average = 0;
$(this).toggle(false);
getLocationUpdate();
});
$('#reset').click(function() {
timerStart = new Date().getTime();
timerInterval = timerStart;
average = 0;
});
});
</script>
</head>
<body>
Current speed: <span id="current"></span><br>
Average speed: <span id="average"></span><br>
Time since last update: <span id="elapsedInterval"></span><br>
Time since reset: <span id="elapsedStart"></span><br>
<button id="start">Start</button><button id="reset">Reset</button>
</body>
</html>