-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.php
165 lines (112 loc) · 2.79 KB
/
server.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
#!/usr/local/bin/php
<?php
include_once("connect2db.php");
?>
<!DOCTYPE html>
<html>
<head>
<META HTTP-EQUIV="refresh" CONTENT="20">
<script type="text/javascript" src="Distance.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyC3wzMp-2Ss2iijSy7mBBKAcDZXOdz-FYg&sensor=false">
</script>
<script>
var counter = "<?php $result =mysql_query("select count(id) from location"); echo mysql_result($result,0); ?>";
document.write(counter);
var latArr = new Array();
var longArr = new Array();
</script>
<?php
$latArray = array();
$query1 = "select `lat` from location";
$result=mysql_query($query1);
while($row = mysql_fetch_array($result)) {
// Append to the array
$latArray[] = $row[0];
}
?>
<script type="text/javascript">
latArr= <?php echo json_encode($latArray ); ?>;
</script>
<?php
$idArray = array();
$query4 = "select `id` from location";
$result4=mysql_query($query4);
while($row = mysql_fetch_array($result4)) {
// Append to the array
$idArray[] = $row[0];
}
?>
<script type="text/javascript">
idArr= <?php echo json_encode($idArray ); ?>;
</script>
<?php
$flagArray = array();
$query3 = "select `flag` from location";
$result3=mysql_query($query3);
while($row = mysql_fetch_array($result3)) {
// Append to the array
$flagArray[] = $row[0];
if($row[0]==1)
{
$result =mysql_query("select `id` from location where `flag`=$row[0]");
echo mysql_result($result,0);
}
}
?>
<script type="text/javascript">
flagArr= <?php echo json_encode($flagArray ); ?>;
</script>
<?php
$longArray = array();
$query2 = "select `long` from location";
$result=mysql_query($query2);
while($row = mysql_fetch_array($result)) {
// Append to the array
$longArray[] = $row[0];
}
?>
<script type="text/javascript">
longArr= <?php echo json_encode($longArray ); ?>;
</script>
<script>
var latSum=0;
var longSum=0;
for (var i=0;i<counter;i++)
{
latSum = latSum + parseFloat(latArr[i]);
}
for (var i=0;i<counter;i++)
{
longSum = longSum + parseFloat(longArr[i]);
}
var meanLat = latSum/counter;
var meanLong = longSum/counter;
document.write(parseFloat(meanLat)+'\n');
document.write(parseFloat(meanLong));
</script>
<script>
function initialize()
{
var mapProp = {
center:new google.maps.LatLng(parseFloat(meanLat),parseFloat(meanLong)),
zoom:19,
mapTypeId:google.maps.MapTypeId.SATELLITE
};
var map=new google.maps.Map(document.getElementById("googleMap")
,mapProp);
for (var i=0;i<counter;i++)
{
var marker = new google.maps.Marker({
position: new google.maps.LatLng(parseFloat(latArr[i]),parseFloat(longArr[i])),
map: map,
title:"Victim"
});
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="googleMap" style="width:1200px;height:600px;"></div>
</body>
</html>