-
Notifications
You must be signed in to change notification settings - Fork 5
/
watch-position.html
41 lines (37 loc) · 941 Bytes
/
watch-position.html
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
<html>
<head>
<title>geolocation.watchPosition demo</title>
</head>
<body>
<div id="output"></div>
<a href="geolocation.html">Click here for a better demo page.</a>
<script>
let output = document.getElementById('output');
function onSuccess(position) {
console.log(position);
output.innerHTML = `
<pre>
latitude: ${position.coords.latitude}
longitude: ${position.coords.longitude}
altitude: ${position.coords.altitude}
accuracy: ${position.coords.accuracy}
altitudeAccuracy: ${position.coords.altitudeAccuracy}
heading: ${position.coords.heading}
speed: ${position.coords.speed}
timestamp: ${position.timestamp}
</pre>
`;
}
function onError(error) {
output.innerHTML =
`<span style="color: red">Error: </span>${error.message} (${error.code})`;
}
options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
}
navigator.geolocation.watchPosition(onSuccess, onError, options);
</script>
</body>
</html>