-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.html
102 lines (81 loc) · 2.29 KB
/
home.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
<!DOCTYPE html>
<html>
<head>
<title>777traker</title>
<meta name="viewport" content="initial-scale=1.0">
<meta http-equiv="Cache-Control" content="no-store">
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<meta charset="utf-8">
<style>
/* adjust map size */
html {
height: 100%;
margin: 0;
padding: 0;
text-align: center;
}
#map {
height: 800px;
width: 1200px;
display: inline-block;
position: relative
}
</style>
</head>
<body>
<!-- display map -->
<div id="map"></div>
<script>
var info;
var maps = null;
var markerArray = [];
var latlng;
function initMap() {
// adjust the map zoom level
var mapOptions = {
center: {lat:13.71225357, lng:100.66889953},
zoom: 13,
}
// set div id="map" to display the map by the mapOption
maps = new google.maps.Map(document.getElementById("map"),mapOptions);
info = new google.maps.InfoWindow();
updatemap();
// call the fuction to update the marker every 5 sec.
window.setInterval(updatemap, 5000);
}
// fuction to clear the old marker before pin the new one
function clear(){
for (var i = 0; i < markerArray.length; i++) {
markerArray[i].setMap(null);
}
}
//fuction to update the map marker
function updatemap(){
//call the json file to get data from the database
$.getJSON( "json.php", function(jsonObj) {
//read the data in jsonObj
$.each(jsonObj, function(i, item){
latlng = new google.maps.LatLng(item.Latitude, item.Longtitude) //define latlng as position
//placing marker
var marker = new google.maps.Marker({
position: latlng,
map: maps,
});
markerArray.push(marker);
maps.panTo(latlng); //move the center to new marker
//pop up info
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
info.setContent(item.Location);
info.open(maps, marker);
}
})
(marker, i));
});
});
clear();
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD7MZdEIb2nLuLBj3LFPdrGix1Ag4SwPy8&callback=initMap" async defer></script>
</body>
</html>