From dc42241515e97d4205f51ee24e34ae75fad656c6 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Fri, 29 Mar 2019 02:38:00 -0600 Subject: [PATCH] Add GeoJSON output format option to getnearby --- api/actions/nearby.php | 29 +++++++++++++++++++++++++++++ api/apisettings.php | 3 ++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/api/actions/nearby.php b/api/actions/nearby.php index 4ac7ed7..d1ff8e9 100644 --- a/api/actions/nearby.php +++ b/api/actions/nearby.php @@ -46,6 +46,35 @@ ob_end_clean(); $nearby = []; +if (!empty($VARS["format"]) && $VARS["format"] == "geojson") { + $geojson = [ + "name" => "Nearby People", + "type" => "FeatureCollection", + "features" => [] + ]; + + foreach ($people as $person) { + $geojson["features"][] = [ + "type" => "Feature", + "geometry" => [ + "type" => "Point", + "coordinates" => [ + $person["longitude"] * 1.0, + $person["latitude"] * 1.0 + ] + ], + "properties" => [ + "id" => $person["publicid"], + "name" => utf8_encode(empty($person["name"]) ? $person["username"] : $person["name"]), + "username" => $person["username"], + "verified" => $person["verified"] == 1 + ] + ]; + } + + exitWithJson($geojson); +} + foreach ($people as $person) { $nearby[] = [ "name" => (empty($person["name"]) ? $person["username"] : $person["name"]), diff --git a/api/apisettings.php b/api/apisettings.php index b45a87d..14a7761 100644 --- a/api/apisettings.php +++ b/api/apisettings.php @@ -72,7 +72,8 @@ $APIS = [ "key" => $keyregex, "latitude" => "/-?[0-9]{2}\.[0-9]+/", "longitude" => "/-?[0-9]{2,3}\.[0-9]+/", - "radius (optional)" => "/[0-9]*\.?[0-9]+/" + "radius (optional)" => "/[0-9]*\.?[0-9]+/", + "format (optional)" => "/(geojson)/" ] ], ];