-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
109 lines (87 loc) · 3.41 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
<!DOCTYPE html>
<html>
<head>
<title>Hackathon</title>
<!-- Include core bootstrap -->
<script type="text/javascript" src="http://studs.gpsgate.com/Services/Core.ashx?xss2=true&deps=true"></script>
<link rel="stylesheet" type="text/css" href="style/main.css">
<!-- Google maps API -->
<!-- https://developers.google.com/maps/documentation/javascript/tutorial -->
<!-- <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true"></script> -->
<script>
// Include session handling (login/logout) + jQuery
goog.require('GpsGate.Session');
// knockout (http://http://knockoutjs.com/)
// goog.require('ko');
</script>
<script>
// Include hackathon web service
GpsGate.require('GpsGate.Server.Hackathon');
</script>
<script type="text/javascript">
function start() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(processGeoData, null, { enableHighAccuracy: true });
navigator.geolocation.watchPosition(processGeoData, null, { enableHighAccuracy: true });
}
}
function processGeoData(data) {
var position = data.coords;
console.log("Got new GEO data", position);
GpsGate.Server.Hackathon.UpdatePosition(position.latitude, position.longitude, position.speed, position.heading);
}
function doLogin() {
var appId = 5;
var username = 'team2';
var password = '1234';
return GpsGate.Session.login(username, password, { appId: appId }).addCallbacks(
function(result) {
console.log('Login OK');
setTimeout(mainProgram, 0); // use timeout "trick" to get out of the deferred callback chain scope
},
function(error) {
console.error("that's a bummer!")
}
);
}
function UpdateNearbyLocations() {
console.log("UpdateNearbyLocations#{call}")
GpsGate.Server.Hackathon.GetNearbyLocations().addCallbacks(
function(response){
var img = jQuery('#compass');
var response = response.filter(function(element) { return element.name !== "GpsGate";})
response.sort(function(a, b) { return a.distance - b.distance; });
// img.empty();
// img.append(jQuery('<img id="big-compass" src="arrow.png" style="-ms-transform:rotate('+response[0].heading+'); -webkit-transform:rotate('+response[0].heading+'deg)"/>')
// );
var ul = jQuery('#locations');
ul.empty()
for (var i = 0; i < response.length; i++) {
ul.append(
jQuery('<li>')
.append(jQuery('<p>').html(response[i].name))
.append(jQuery('<p>').html(response[i].distance + "m"))
.append(jQuery('<img id="small-compass" src="arrow.png" style="-ms-transform:rotate('+response[i].heading+'); -webkit-transform:rotate('+response[i].heading+'deg)"/>'))
)
}
setTimeout(UpdateNearbyLocations, 1000);
}
)
}
function mainProgram() {
// do something
console.log('app.main');
start();
// Get some users
UpdateNearbyLocations();
}
jQuery(document).ready(doLogin);
</script>
</head>
<body>
<div id="container">
<div id="compass"></div>
<ul id="locations"></ul>
</div>
</body>
</html>