-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeo.html
86 lines (79 loc) · 2.65 KB
/
geo.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
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="-1" />
<script type="text/javascript">
/*
Quick hack that uses the (mobile) browser's geolocation API to update the
beacon sensor (not part of the spaceAPI yet at the time of writing)
Simply navigate to:
geo.php?key=<API_KEY>&address=<SENSOR_ADDRESS>
where <API_KEY> is the API key defined in index.php
and <SENSOR_ADDRESS> is the name of the beacon sensor to set or update
Note that this will drain the battery significantly.
*/
function window_load()
{
if ( navigator.geolocation )
var watchID = navigator.geolocation.watchPosition( message, message, { enableHighAccuracy : true } );
else
message( "Geolocation not supported" );
}
function message( _message )
{
var message;
if ( typeof _message === "string" )
{
message = _message;
}
else
{
if ( _message.message )
{
message = _message.message;
}
else if ( _message.coords )
{
message = "Latitude: " + _message.coords.latitude +
"\nLongitude: " + _message.coords.longitude +
"\nAccuracy: " + _message.coords.accuracy +
"\nAltitude: " + _message.coords.altitude +
"\nAccuracy(alt): " + _message.coords.altitudeAccuracy +
"\nheading: " + _message.coords.heading +
"\nSpeed " + _message.coords.speed +
"\ntimestamp: " + new Date( _message.timestamp );
if ( !document.location.search )
message += "\nadd ?key=API_KEY&address=SENSOR_ADDRESS";
else
{
var xhr = new XMLHttpRequest();
// Fetch (max number, excluding blank line) of lines (TODO: starting from timestamp)
xhr.open( "GET", "/spaceAPI/" + document.location.search + "&update=sensors&type=beacon&lat=" + _message.coords.latitude + "&lon=" + _message.coords.longitude + "&accuracy=" + _message.coords.accuracy );
xhr.onload = function()
{
$("info").textContent += "\nok";
}
xhr.send( );
}
}
else
{
message = "unknown message";
}
}
$("info").textContent = message;
}
function $( _o )
{
return document.querySelector( "#" + _o );
}
window.addEventListener( "load", window_load, false );
</script>
</head>
<body>
<pre id="info">initializing..</pre>
</body>
</html>