This repository was archived by the owner on Apr 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
138 lines (114 loc) · 3.89 KB
/
index.html
File metadata and controls
138 lines (114 loc) · 3.89 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!--
FindMyArduino
Tested with ESP32 and GY-GPS6MV2 module
Version: 1.0
Authors: Tamer
Updated: 25-09-2017
-->
<meta charset="UTF-8">
<!-- Load Google Maps API before doing anything else. Start with // to make it work on both HTTP and HTTPS. -->
<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?key=AIzaSyA2LReWhDUeiIsEqcQot3AioOsK_5FTnIQ"></script><!-- Yes you can use my API key... -->
<style>
#map-canvas {
height: 400px;
}
</style>
<h1>FindMyArduino</h1>
<p>Author: Qarizma (Minor Smart Industry)</p>
<div id="map-canvas"></div>
<p id="coordinates"><font color="orange">Connecting...</font></p>
<script type="text/javascript">
var url = '//YOURLINK.COM/';
var map;
var json;
var gpsdata;
var curTime;
var remTime;
var markers = [];
var positions = [
['GPS', 51.988996, 5.949398, 4],
];
function setMarkers(locations) {
for (var i = 0; i < locations.length; i++) {
var beach = locations[i];
var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
animation: google.maps.Animation.DROP,
title: beach[0],
zIndex: beach[3],
// Uncomment below to use a custom marker on the map.
//icon: url + 'icon.png'
});
// Push marker to markers array
markers.push(marker);
}
}
function reloadMarkers() {
readTextFile(url + "gps.json?" + Math.random());
var json = JSON.parse(gpsdata);
positions = [['GPS', json[1], json[0], 4],];
var readableTime = new Date(json[2] * 1000);
curTime = new Date();
remTime = json[2];
// Nice function to find out if the Arduino is online by comparing timestamps.
if ((curTime.getTime()/1000-remTime) > 10) {
console.log('Arduino: Offline Lat:' + json[1] + ' Lon: ' + json[0] + ' Update: ' + readableTime);
document.getElementById("coordinates").innerHTML = "<font color=\"red\">ARDUINO OFFLINE</font> <br>Lat: " + json[1] + "<br> Lon: " + json[0] + "<br> Update: " + readableTime;
} else {
console.log('Arduino: Online Lat:' + json[1] + ' Lon: ' + json[0] + ' Update: ' + readableTime);
document.getElementById("coordinates").innerHTML = "<font color=\"green\">ARDUINO ONLINE</font> <br>Lat: " + json[1] + "<br> Lon: " + json[0] + "<br> Update: " + readableTime;
}
// Move map to marker location.
moveToLocation(json[1], json[0]);
// Loop through markers and set map to null for each
for (var i=0; i<markers.length; i++) {
markers[i].setMap(null);
}
// Reset the markers array
markers = [];
// Call set markers to re-add markers
setMarkers(positions);
}
function initialize() {
// Read remote JSON data with GPS info to start with.
readTextFile(url + "gps.json");
var mapOptions = {
zoom: 25,
center: new google.maps.LatLng(51.988996, 5.949398), // start coordinates of HAN campus.
mapTypeId: google.maps.MapTypeId.SATELLITE
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
// Set the marker(s).
setMarkers(positions);
}
initialize();
// Set an interval. 3000ms = 3 seconds.
window.setInterval(function(){
// Reload the markers every X seconds.
reloadMarkers();
}, 3000);
// Function to focus the map on a coordinate.
function moveToLocation(lat, lng){
var center = new google.maps.LatLng(lat, lng);
map.panTo(center);
}
// JS function to read data from remote file.
function readTextFile(file)
{
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function ()
{
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
gpsdata = rawFile.responseText;
}
}
}
rawFile.send(null);
}
</script>