-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththere.js
More file actions
76 lines (67 loc) · 1.73 KB
/
there.js
File metadata and controls
76 lines (67 loc) · 1.73 KB
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
function npl(val, add) {
if(val!=null) {
return val+add;
}
return '';
}
function didLocate(position) {
setActivityStatus('done');
if(position.coords) {
var coo = position.coords;
setPosVal(coo.latitude, coo.longitude, npl(coo.altitude, ', ')+'±'+coo.accuracy, true);
} else {
setPosVal('??','??','Invalid');
}
}
function locateDidFail(error) {
var reason='‽';
setActivityStatus('stop');
switch(error.code) {
case error.TIMEOUT:
reason = 'TIMEOUT';
break;
case error.PERMISSION_DENIED:
reason = 'DENIED';
break;
}
setPosVal('--','--', reason);
}
function setActivityStatus(state) {
document.getElementById('circles').setAttribute('class', state);
}
function setPosVal(latitude, longitude, accuracy, isValid) {
setTextForNodeId(latitude, 'lat');
setTextForNodeId(longitude, 'long');
setTextForNodeId(accuracy, 'acc');
if(isValid) {
document.getElementById('c0').setAttribute('href','http://maps.google.com/?q='+latitude+','+longitude+'+(There)');
} else {
document.getElementById('c0').setAttribute('href','');
}
}
function setTextForNodeId(text, nodeid) {
var node = document.getElementById(nodeid);
if(node) {
clearNode(node);
node.appendChild(document.createTextNode(text));
}
}
function clearNode(node) {
while(node.firstChild) {
node.removeChild(node.firstChild);
}
}
function startLocating() {
setActivityStatus('pre');
setPosVal('--','--','--');
if(navigator.geolocation) {
setActivityStatus('pulse');
setPosVal('…','…','…');
navigator.geolocation.getCurrentPosition(didLocate, locateDidFail,
{maximumAge:60000, timeout:10000});
}
}
window.addEventListener('load', function() {
document.getElementById('acc').addEventListener('click', startLocating, false);
startLocating();
}, false);