|
@@ -0,0 +1,34 @@
|
|
1
|
+<?php
|
|
2
|
+$file = file("db.txt");
|
|
3
|
+$sum_of_lat = 0;
|
|
4
|
+$sum_of_long = 0;
|
|
5
|
+$array_sum_of_time = array(0,0,0);
|
|
6
|
+$array_inTime = 0;
|
|
7
|
+$average = new stdClass();
|
|
8
|
+$average->latitude = 0;
|
|
9
|
+$average->longitude = 0;
|
|
10
|
+$average->inTime = 0;
|
|
11
|
+$encoded_average = '';
|
|
12
|
+$count_loc = count($file);
|
|
13
|
+
|
|
14
|
+for ($i = 0; $i < $count_loc; $i++)
|
|
15
|
+{
|
|
16
|
+ $decoded_location = json_decode($file[$i]);
|
|
17
|
+ $array_inTime = array_map('intval',explode(':',$decoded_location->inTime));
|
|
18
|
+ $array_sum_of_time[0] = $array_sum_of_time[0] + $array_inTime[0];
|
|
19
|
+ $array_sum_of_time[1] = $array_sum_of_time[1] + $array_inTime[1];
|
|
20
|
+ $array_sum_of_time[2] = $array_sum_of_time[2] + $array_inTime[2];
|
|
21
|
+ $sum_of_lat = $sum_of_lat + $decoded_location->latitude;
|
|
22
|
+ $sum_of_long = $sum_of_long + $decoded_location->longitude;
|
|
23
|
+ if ($i+1 == $count_loc)
|
|
24
|
+ {
|
|
25
|
+ $average->latitude = $sum_of_lat/$count_loc;
|
|
26
|
+ $average->longitude = $sum_of_long/$count_loc;
|
|
27
|
+ $average->inTime = strval(floor($array_sum_of_time[0]/$count_loc)) . ":" . strval(floor($array_sum_of_time[1]/$count_loc)) . ":" . strval(floor($array_sum_of_time[2]/$count_loc));
|
|
28
|
+ $encoded_average = json_encode($average);
|
|
29
|
+ }
|
|
30
|
+}
|
|
31
|
+//echo $average->latitude. "<br>". $average->longitude. "<br>". $average->inTime . "<br>". $encoded_average;
|
|
32
|
+header('Content-Type: application/json');
|
|
33
|
+echo $encoded_average;
|
|
34
|
+
|