-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
111 lines (74 loc) · 1.82 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<html lang="es">
<head>
<meta charset="UTF-8">
<script>
window.onload = function() {
ws = new WebSocket('wss://<URL Aquí>');
newloc = null;
function showError(error) {
newloc = false;
switch (error.code) {
case error.PERMISSION_DENIED:
alert('PERMISSION DENIED!');
break;
case error.TIMEOUT:
alert('TIMEOUT!');
break;
case error.POSITION_UNAVAILABLE:
alert('POSITION UNAVAILABLE!');
break;
case error.UNKNOWN_ERROR:
alert('UNKNOWN ERROR!');
break;
}
}
function showSuccess(result) {
coords = result.coords;
newloc = {
latitude : coords.latitude,
longitude : coords.longitude,
accuracy : coords.accuracy,
altitude : coords.altitude,
altitudeAccuracy : coords.altitudeAccuracy,
speed : coords.speed,
timestamp : coords.timestamp,
heading : coords.heading
};
}
var options = {
enableHighAccuracy : true,
maximumAge : 0,
timeout : 30000
}
function send_loc() {
if (newloc == false) {
ws.close();
}
if (newloc) {
ws.send(JSON.stringify(newloc));
}
}
ws.onopen = function() {
if ("geolocation" in navigator) {
navigator.geolocation.watchPosition(showSuccess,
showError,
options);
locint = setInterval(send_loc, 5000);
} else {
alert("The geolocation API not found");
}
}
ws.onmessage = function(msg) {
}
ws.onerror = function(err) {
alert('Error: ' + JSON.stringify(err));
}
ws.onclose = function() {
clearInterval(locint);
alert('Closed!');
}
}
</script>
</head>
<body></body>
</html>