-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
146 lines (131 loc) · 4.96 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
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
139
140
141
142
143
144
145
146
<!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 path=[{lat:26.9157,lng:70.9083}];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(26.9157, 70.9083),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var lineSymbol = {
path: 'M 0,-1 0,1',
strokeOpacity: 1,
scale: 4
};
/* function getDevices() {
var request = {
url: "http://204.197.244.110/~ezenroutedemo/track_demo/api/v1/public/getDevicesLocation"
};
setInterval(function () {
$.ajax(request).done(function (response) {
var devices = response.data[0].devices;
if (devices.length > 0) {
locations = [];
for (var i = 0; i < devices.length; i++) {
locations.push([devices[i].deviceId, devices[i].latitude, devices[i].longitude, i]);
path.push({lat:Number(locations[i][1]),lng:Number(locations[i][2])});
var flightPath = new google.maps.Polyline({
path: path,
strokeOpacity: 0,
icons:[{
icon: lineSymbol,
offset: '0',
repeat: '30px'
}],
map: map
});
console.log(locations);
console.log(path);
}
var latlng = new google.maps.LatLng(devices[0].latitude, devices[0].longitude);
map.setCenter(latlng);
}
});
//flightPath.setMap(map);
refreshMap();
}, 5000);
}
*/
var marker;
marker=new google.maps.Marker();
function getLocation() {
var request = {
url: "https://webgeekssih-895b1.firebaseio.com/.json"
};
setInterval(function () {
$.ajax(request).done(function (response) {
var lat,lng;
locations=response.GPS;
console.log(locations)
console.log(Object.keys(locations));
keys=Object.keys(locations);
//console.log(locations[keys[0]].longitude);
keys.forEach(function(entry){
lat=locations[[entry]].latitude;
lng=locations[[entry]].longitude;
path.push({lat:Number(lat),lng:Number(lng)});
console.log(path);
})
var flightPath = new google.maps.Polyline({
path: path,
strokeOpacity: 0,
icons:[{
icon: lineSymbol,
offset: '0',
repeat: '30px'
}],
map: map
});
marker.setMap(null);
marker.setPosition({lat,lng});
marker.setMap(map);
});
//refreshMap();
},5000)}
function refreshMap() {
var marker, i;
keys.forEach(function(entry){
var lat=locations[[entry]].latitude;
var lng=locations[[entry]].longitude;
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>