-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
83 lines (75 loc) · 1.83 KB
/
index.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
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
80
81
82
83
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<button id="gps" onclick="javascript:gps();">GPS</button>
<div id="iploc"></div><br>
<div id="lowloc"></div><br>
<div id="highloc"></div>
<script>
function gps() {
iploc();
lowloc();
highloc();
}
function dataformat(data) {
const coords = data.coords;
return {
timestamp: data.timestamp,
isHighAccuracy: data.isHighAccuracy,
accuracy: coords.accuracy,
latitude: coords.latitude,
longitude: coords.longitude,
altitude: coords.altitude,
altitudeAccuracy: coords.altitudeAccuracy,
heading: coords.heading,
speed: coords.speed
};
}
function getiploc(data) {
getloc(data, "#iploc");
}
function getlowloc(data) {
getloc(dataformat(data), "#lowloc");
}
function gethighloc(data) {
getloc(dataformat(data), "#highloc");
}
function getloc(data, src) {
console.log(data);
document.querySelector(src).innerText = JSON.stringify(data).replace(/\n/mg, "<br>");
}
function iploc() {
const script = document.createElement('script');
script.src = 'https://ipinfo.io?callback=getiploc';
document.body.appendChild(script);
document.body.removeChild(script);
}
function lowloc() {
navigator.geolocation.getCurrentPosition(
getlowloc,
getlowloc,
{
enableHighAccuracy: false,
timeout: 10000,
maximumAge: 0
}
);
}
function highloc() {
navigator.geolocation.getCurrentPosition(
gethighloc,
gethighloc,
{
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 0
}
);
}
</script>
</body>
</html>