You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.1 KiB
PHP

<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation;
$userlocation = GeoLocation::fromDegrees($VARS["latitude"], $VARS["longitude"]);
// Update player ping/location
$database->update("players", [
"latitude" => $VARS["latitude"],
"longitude" => $VARS["longitude"],
"lastping" => date("Y-m-d H:i:s")
], [
"accountid" => getRequestUser()->getUID()
]);
$radius = 2;
if (!empty($VARS["radius"])) {
$radius = min(10.0, $VARS["radius"] * 1.0);
}
$searchbounds = $userlocation->boundingCoordinates($radius, "miles");
ob_flush();
$people = $database->debug()->select("players", [
"accountid",
"level",
"nickname",
"energy",
"maxenergy",
"latitude",
"longitude",
"teamid"
], [
"AND" => [
'latitude[<>]' => [$searchbounds[0]->getLatitudeInDegrees(), $searchbounds[1]->getLatitudeInDegrees()],
'longitude[<>]' => [$searchbounds[0]->getLongitudeInDegrees(), $searchbounds[1]->getLongitudeInDegrees()],
"lastping[>]" => date("Y-m-d H:i:s", strtotime("-1 minute")),
"kick" => ""
],
"LIMIT" => 100
]
);
$query = ob_get_contents();
ob_clean();
$people = $database->query($query)->fetchAll();
$nearby = [];
$geojson = [
"status" => "OK",
"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["accountid"],
"name" => $person["nickname"],
"latitude" => $person["latitude"],
"longitude" => $person["longitude"],
"team" => $person["teamid"]
]
];
}
exitWithJson($geojson);