-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
29 lines (25 loc) · 786 Bytes
/
api.php
File metadata and controls
29 lines (25 loc) · 786 Bytes
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
<?php
$long = isset($_GET["long"]) ? $_GET["long"] : 0;
$lat = isset($_GET["lat"]) ? $_GET["lat"] : 0;
$range = isset($_GET["range"]) ? $_GET["range"] : 0;
$redis = new Redis();
$redis->pconnect('127.0.0.1');
$hosts = $redis->geoRadius("hs:nodes:geo", $long, $lat, $range, "km", ["WITHCOORD"]);
$parsed = array(
"type" => "FeatureCollection",
"features" => array()
);
foreach($hosts as $host){
$ep = unpack("Pip/Pip2/Sport", $host[0]);
$nh = inet_ntop(pack("PP", $ep["ip"], $ep["ip2"]));
array_push($parsed["features"], array(
"type" => "Feature",
"geometry" => array(
"type" => "Point",
"coordinates" => array(floatval($host[1][0]), floatval($host[1][1]))
)
));
}
header('Content-Type: application/json');
echo json_encode($parsed);
?>