-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetcurrentlocation.html
More file actions
35 lines (29 loc) · 874 Bytes
/
getcurrentlocation.html
File metadata and controls
35 lines (29 loc) · 874 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
35
<!DOCTYPE html>
<html>
<head>Test Website</head>
<body>
<h1>Test Geolocation Get Current Position</h1>
<button id="getLocButton" type="button" onclick="getPosition()">Get Current 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 Current Position");
navigator.geolocation.getCurrentPosition(success, error, geolocationOptions);
}
</script>