-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatchposition.html
More file actions
34 lines (29 loc) · 862 Bytes
/
watchposition.html
File metadata and controls
34 lines (29 loc) · 862 Bytes
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
<!DOCTYPE html>
<html>
<head>Test Website</head>
<body>
<h1>Test Geolocation Get Watch Position</h1>
<button id="getLocButton" type="button" onclick="getPosition()">Get Watch Position</button>
<ul id="locations">
</ul>
</body>
</html>
<script>
const geolocationOptions = {
enableHighAccuracy: true,
};
function success(pos) {
const crd = pos.coords;
const ul = document.getElementById('locations');
let li = document.createElement('li');
li.innerHTML = `Lat: ${crd.latitude} Lon: ${crd.longitude} Acc: ${crd.accuracy}`;
ul.appendChild(li);
}
function error(err) {
console.warn(`ERROR(${err.code}): ${err.message}`);
}
function getPosition(){
console.log("Get Watch Position");
navigator.geolocation.watchPosition(success, error, geolocationOptions);
}
</script>