-
Notifications
You must be signed in to change notification settings - Fork 0
/
index - Copy.html
126 lines (113 loc) · 4.06 KB
/
index - Copy.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Track Devices</title>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="http://maps.google.com/maps/api/js?key=AIzaSyBVFpBEujfwOenwdWiB6D2D1xagS0HYxEg"
type="text/javascript"></script>
</head>
<body>
<div id="map"></div>
<script>
var locations = [];
var keys=[];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 19,
//center: new google.maps.LatLng(26.9124, 75.7873),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var lineSymbol = {
path: 'M 0,-1 0,1',
strokeOpacity: 1,
scale: 4
};
var marker;
marker=new google.maps.Marker();
function getLocation() {
var path=[];
var start,finish;
var locations;
var request = {
url: "https://webgeekssih-895b1.firebaseio.com/.json"
};
setInterval(function () {
$.ajax(request).done(function (response) {
if(response!=null){
var keys=Object.keys(response);
console.log(keys);
console.log();
locations=response[keys[1]];
//locations=response.Guard2locations;
console.log(locations);
if(locations.length>0){
start={lat:locations[0].lat,lng:locations[0].lng};
path=[];
var i;
for(i=0;i<locations.length;i++)
{
marker.setMap(null);
path.push({lat:locations[i].lat,lng:locations[i].lng});
map.setCenter({lat:locations[i].lat,lng:locations[i].lng});
marker.setPosition({lat:locations[i].lat,lng:locations[i].lng});
marker.setMap(map);
}
finish={lat:locations[locations.length-1].lat,lng:locations[locations.length-1].lng};
console.log(path);
}
else{
alert("Tracking is not started yet!");
}
}
else{
alert("There is no guard!");
}
var flightPath = new google.maps.Polyline({
path: path,
strokeOpacity: 0,
icons:[{
icon: lineSymbol,
offset: '0',
repeat: '30px'
}],
map: map
});
});
},5000)}
/*
function refreshMap() {
var marker, i;
for(var i=0;i<keys.length;i++){
marker = new google.maps.Marker({
position: new google.maps.LatLng(lat,lng),
map: map
});
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
})
}
}
*/
getLocation();
</script>
</body>
</html>