-
Notifications
You must be signed in to change notification settings - Fork 1
/
map.php
185 lines (148 loc) · 4.22 KB
/
map.php
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/* Database connection settings */
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'kevann';
$mysqli = new mysqli($host,$user,$pass,$db) or die($mysqli->error);
$coordinates = array();
$latitudes = array();
$longitudes = array();
// Select all the rows in the markers table
$query = "SELECT `locationLatitude`, `locationLongitude` FROM `location_tab` ";
$result = $mysqli->query($query) or die('data selection for google map failed: ' . $mysqli->error);
while ($row = mysqli_fetch_array($result)) {
$latitudes[] = $row['locationLatitude'];
$longitudes[] = $row['locationLongitude'];
$coordinates[] = 'new google.maps.LatLng(' . $row['locationLatitude'] .','. $row['locationLongitude'] .'),';
}
//remove the comaa ',' from last coordinate
$lastcount = count($coordinates)-1;
$coordinates[$lastcount] = trim($coordinates[$lastcount], ",");
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" href="bootstrap-5.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="style12.css">
<title>Map | View</title>
</head>
<style>
body{
font-family: Arial;
margin: 5px 100px 0px 100px;
padding: 0;
color: white;
text-align: center;
}
.active{
background-color: #DD4F43;
}
.form-area{
float: right;
display: table-column;
margin-bottom: 10px;
color: white;
}
.btn-submit {
outline: 0;
background: #F4BA0F;
width: 120px;
border: 0;
padding: 8px;
color: white;
font-size: 12px;
cursor: pointer;
}
.btn-submit:hover, .form button:active{
background: #555652;
}
#userTable{
background: #222;
}
.outer-scontainer {
color: #E8E9EB;
background: #333;
border: #555652 1px solid;
padding-top: 30px;
}
.outer-scontainer table {
/*border-collapse: collapse;*/
width: 100%;
}
.outer-scontainer th {
border: 1px solid #555652;
padding: 5px;
text-align: center;
}
.outer-scontainer td {
border: 1px solid #555652;
padding: 5px;
text-align: center;
}
</style>
<body>
<?php
require_once('navbar.html');
?>
<div class="outer-scontainer">
<div class="row">
<form class="form-horizontal" action="" method="post" name="frmCSVImport" id="frmCSVImport" enctype="multipart/form-data">
<div class="form-area">
<button type="submit" id="submit" name="import" class="btn-submit">RELOAD DATA</button><br />
</div>
</form>
</div>
<div id="map" style="width: 100%; height: 80vh;"></div>
<script>
function initMap() {
var mapOptions = {
zoom: 18,
center: {<?php echo'lat:'. $latitudes[0] .', lng:'. $longitudes[0] ;?>}, //{lat: --- , lng: ....}
mapTypeId: google.maps.MapTypeId.SATELITE
};
var map = new google.maps.Map(document.getElementById('map'),mapOptions);
var RouteCoordinates = [
<?php
$i = 0;
while ($i < count($coordinates)) {
echo $coordinates[$i];
$i++;
}
?>
];
var RoutePath = new google.maps.Polyline({
path: RouteCoordinates,
geodesic: true,
strokeColor: '#1100FF',
strokeOpacity: 1.0,
strokeWeight: 10
});
mark = 'images/mark.png';
flag = 'images/flag.png';
startPoint = {<?php echo'lat:'. $latitudes[0] .', lng:'. $longitudes[0] ;?>};
endPoint = {<?php echo'lat:'.$latitudes[$lastcount] .', lng:'. $longitudes[$lastcount] ;?>};
var marker = new google.maps.Marker({
position: startPoint,
map: map,
icon: mark,
title:"Start point!",
animation: google.maps.Animation.BOUNCE
});
var marker = new google.maps.Marker({
position: endPoint,
map: map,
icon: flag,
title:"End point!",
animation: google.maps.Animation.DROP
});
RoutePath.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<!--remenber to put your google map key-->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC-dFHYjTqEVLndbN2gdvXsx09jfJHmNc8&callback=initMap"></script>
</body>
</html>