-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocations.php
46 lines (31 loc) · 912 Bytes
/
locations.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
<?php
$long = $_GET["long"];
$lat = $_GET["lat"];
$query = array_key_exists("query", $_GET) ? $_GET["query"] : NULL;
$price = array_key_exists("price", $_GET) ? $_GET["price"] : NULL;
$rad = array_key_exists("rad", $_GET) ? $_GET["rad"] : NULL;
$num = array_key_exists("num", $_GET) ? $_GET["num"] : NULL;
$command = "./kdtree";
if(!is_null($query))
$command .= " -q " . $query;
if(!is_null($price))
$command .= " -p " . $price;
if(!is_null($rad))
$command .= " -r " . $rad;
if(!is_null($num))
$command .= " -k " . $num;
$command .= " " . $long . " " . $lat;
//echo $command . "\n";
$handle = popen($command, "r");
//open json
$str = file_get_contents('./locations.json');
$data = json_decode($str, TRUE);
$results = array();
$i = 0;
while ($s = fgets($handle, 1024)) {
if($i >= 26) break;
//echo $s;
$results[$i++] = $data[intval(chop($s))];
}
echo json_encode($results);
pclose($handle);