-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndex.html
More file actions
122 lines (109 loc) · 3.43 KB
/
Index.html
File metadata and controls
122 lines (109 loc) · 3.43 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
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
112
113
114
115
116
117
118
119
120
121
122
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GAP Check In</title>
<style type="text/css">
body
{
background-color: #054F87;
color: white;
font-family: "Trebuchet MS" , Verdana, Helvetica, "Sans-Serif";
}
.checkinButton
{
height: 50px;
font-weight: bold;
}
</style>
<script type="text/javascript" src="assets/js/jquery-1.8.0.min.js"></script>
<script language="javascript">
function checkin() {
$("#status").html("");
writeStatus("Checking in at " + new Date());
//writeStatus("Getting location");
getlocation(reportPosition);
}
function getlocation(callback) {
navigator.geolocation.getCurrentPosition(
function (position) {
writeStatus("Latitude:" + position.coords.latitude + " Longitude:" + position.coords.longitude);
//console.log(position);
callback(position);
},
// next function is the error callback
function (error) {
switch (error.code) {
case error.TIMEOUT:
writeStatus('GPS Timeout');
break;
case error.POSITION_UNAVAILABLE:
writeStatus('GPS Position unavailable');
break;
case error.PERMISSION_DENIED:
writeStatus('GPS Permission denied');
break;
case error.UNKNOWN_ERROR:
writeStatus('GPS Unknown error');
break;
}
});
}
function reportPosition(position) {
var tenant = "1234";
var device = "123456789012346";
var speed = position.coords.speed ? position.coords.speed : 0;
var heading = position.coords.heading ? position.coords.heading : 0;
var altitude = position.coords.altitude ? position.coords.altitude : 0;
var message = {
"MessageType": "CheckIn",
"Message": "Checked in",
"Position":
{
"Latitude": position.coords.latitude,
"Longitude": position.coords.longitude,
"Speed": speed,
"Heading": heading,
"Altitude": altitude,
"Accuracy": position.coords.accuracy,
"LocationSource": "Gps",
"GpsTimestamp" : ISODateString(new Date(position.timestamp))
},
"SentFromDevice": ISODateString(new Date()),
"EmergencyState": "None"
}
writeStatus("Checking in...");
jQuery.ajax("http://api.globalalerting.com/" + tenant + "/devices/" + device + "/momessages", {
cache: false,
type: "POST",
headers: {},
data: message,
dataType: "json",
complete: function (jqXHR, textStatus) {
if (textStatus == "success")
writeStatus("Check-in successful");
else
writeStatus("An error occured, Please try again");
}
});
//writeStatus(JSON.stringify(message));
}
function ISODateString(d) {
function pad(n) { return n < 10 ? '0' + n : n }
return d.getUTCFullYear() + '-' + pad(d.getUTCMonth() + 1) + '-' + pad(d.getUTCDate()) + 'T' + pad(d.getUTCHours()) + ':' + pad(d.getUTCMinutes()) + ':' + pad(d.getUTCSeconds()) + 'Z'
}
function writeStatus(message) {
$("#status").html(message + "<br/>")
}
if (!navigator.geolocation) {
alert('GPS API not supported on this device');
}
</script>
</head>
<body>
<center>
<h1>GAP Check-In</h1>
<button onclick="checkin();" class="checkinButton">Check In</button><br/><br/>
<div id="status"></div> <img src="http://api2.globalalerting.com/Content/powered-by-gap.png" />
</center>
</body>
</html>