|
@@ -0,0 +1,68 @@
|
|
1
|
+
|
|
2
|
+<?php
|
|
3
|
+header('Content-Type: application/json');
|
|
4
|
+function distanceMeters($lat1, $lon1, $lat2, $lon2)
|
|
5
|
+{
|
|
6
|
+ $x = deg2rad( $lon1 - $lon2 ) * cos( deg2rad( $lat1 ) );
|
|
7
|
+ $y = deg2rad( $lat1 - $lat2 );
|
|
8
|
+ $dist = 6371000.0 * sqrt( $x*$x + $y*$y );
|
|
9
|
+
|
|
10
|
+ return $dist;
|
|
11
|
+}
|
|
12
|
+ $db = file('db.txt');
|
|
13
|
+ $sum_of_lat = 0;
|
|
14
|
+ $sum_of_long = 0;
|
|
15
|
+ $sum_of_time = 0;
|
|
16
|
+ $array_time = array();
|
|
17
|
+ $average = new stdClass;
|
|
18
|
+ $average->latitude = 0;
|
|
19
|
+ $average->longitude = 0;
|
|
20
|
+ $average->inTime = 0;
|
|
21
|
+ $average->parada = '';
|
|
22
|
+ $db_size = count($db);
|
|
23
|
+ $distances=[];
|
|
24
|
+ $paradas = array(
|
|
25
|
+ "Generales" => array(18.404916, -66.044828),
|
|
26
|
+ "Natu_1" => array(18.403663, -66.045529),
|
|
27
|
+ "Natu_2" => array(18.403769, -66.046572),
|
|
28
|
+ "Centro" => array( 18.403898, -66.048255),
|
|
29
|
+ "Biblio" => array(18.403994, -66.049781),
|
|
30
|
+ "Merenderos" => array(18.406345, -66.050197),
|
|
31
|
+ "Leyes" => array (18.406069, -66.047733),
|
|
32
|
+ "Complejo" => array(18.406503, -66.046121),
|
|
33
|
+ "ROTC_Entrada" => array(18.406083, -66.043605),
|
|
34
|
+ "ROTC_Estacionamiento" => array( 18.407121, -66.042053)
|
|
35
|
+ );
|
|
36
|
+ for ($i = 0; $i < $db_size; $i++)
|
|
37
|
+ {
|
|
38
|
+ $decoded_location = json_decode($db[$i]);
|
|
39
|
+ $sum_of_lat += $decoded_location->latitude;
|
|
40
|
+ $sum_of_long += $decoded_location->longitude;
|
|
41
|
+ array_push($array_time,$decoded_location->inTime);
|
|
42
|
+ if($i+1 == $db_size)
|
|
43
|
+ {
|
|
44
|
+ $average->latitude = $sum_of_lat/$db_size;
|
|
45
|
+ $average->longitude = $sum_of_long/$db_size;
|
|
46
|
+ $average->inTime = date("h:i:s a",(array_sum(array_map('strtotime',$array_time)))/$db_size);
|
|
47
|
+ }
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ foreach($paradas as &$thing)
|
|
51
|
+ {
|
|
52
|
+ $plo = distanceMeters($average->latitude, $average->longitude, $thing[0], $thing[1]);
|
|
53
|
+ array_push($distances,$plo);
|
|
54
|
+ //echo $distances;
|
|
55
|
+
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ //echo $encoded_average;
|
|
59
|
+ $indice = array_search(min($distances),$distances);
|
|
60
|
+ $checking = array_keys($paradas);
|
|
61
|
+ //$encoded_average = json_decode($encoded_avarage);
|
|
62
|
+
|
|
63
|
+ $average->parada = $checking[$indice];
|
|
64
|
+ $encoded_average =json_encode($average);
|
|
65
|
+ echo $encoded_average;
|
|
66
|
+ //echo "pol";
|
|
67
|
+ //echo $average;
|
|
68
|
+?>
|