/
getThematicWp.php
100 lines (87 loc) · 2.52 KB
/
getThematicWp.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
<?php
// 1 POST LAT, LON AND WALKING DISTANCE BETWEEN START POINT AND DESTINATION POINT
/*
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
*/
$DEBUGMODE = false;
dbConnect();
function dbConnect(){
//Connection to database
$dbHost = 'localhost';
$dbUser = 'hot_thess';
$dbPass = 'hot_thess1234';
$dbName = 'hot_thess';
$connection = mysqli_connect($dbHost, $dbUser, $dbPass, $dbName)
or die('Error Connecting to MySQL DataBase');
mysqli_set_charset($connection, "utf8");
$data = file_get_contents('php://input');
$data = json_decode($data,true);
dbSelect($connection,$data);
}
function dbSelect($con,$data){
global $DEBUGMODE;
$waypoints=array();
$distance=0;
$slat = $data['slat'];
$slon = $data['slon'];
$elat = $data['elat'];
$elon = $data['elon'];
$distance = $data['d'];
$theme = $data['t'];
if($DEBUGMODE){
echo "call haversine($slat,$slon,$elat,$elon,$theme,$distance)";
print_r($data);
}
unset($data['d']);
unset($data['t']);
//GET THEMATIC ROUTES POIS FROM DATABASE
$result = mysqli_query($con,"call haversine(".$slat.",".$slon.",".$elat.",".$elon.",'".$theme."',".$distance.")");
while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
$waypoints[] = $row;
}
sort($waypoints);
filterWp($waypoints);
if($DEBUGMODE){
//echo "<pre>";
print_r($waypoints);
//echo "</pre>";
}
dbClose($con);
}
function filterWp($waypoints){
global $DEBUGMODE;
$filteredWp = array();
$region=0;
$previous_dest=$distance;
foreach($waypoints as $key=>$value){
if(isset($value['bid'])){
if($region == $value['bid']){
unset($waypoints[$key]);
continue;
}
if($key==0){
$filteredWp[] = array("bid"=> $value['bid'], "lat"=>$value['lat'], "lon"=>$value['lon'], "name"=>$value['name'], "start"=>$value['d_start'], "dest"=>$value['d_dest'], "descr"=>$value['description'], "image"=>$value['image'], "url"=>$value['url']);
$region = $value['bid'];
$previous_dest = $value['d_dest'];
} else {
if($value['d_dest']<$previous_dest){
$filteredWp[] = array("bid"=> $value['bid'], "lat"=>$value['lat'], "lon"=>$value['lon'], "name"=>$value['name'], "start"=>$value['d_start'], "dest"=>$value['d_dest'],"descr"=>$value['description'], "image"=>$value['image'], "url"=>$value['url']);
$previous_dest = $value['d_dest'];
$region = $value['bid'];
}
}
}
}
if($DEBUGMODE){
//echo "<pre>";
print_r($filteredWp);
//echo "</pre>";
}else
echo json_encode($filteredWp,JSON_NUMERIC_CHECK);
}
function dbClose($con){
mysqli_close($con);
}
?>