Get nearby places and players API, improve DB schema, ignore zero-weighted items when picking
parent
af13a70976
commit
f9afcbe5d8
@ -1,97 +0,0 @@
|
|||||||
<?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"]);
|
|
||||||
|
|
||||||
$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("accounts", [
|
|
||||||
"publicid",
|
|
||||||
"name",
|
|
||||||
"username",
|
|
||||||
"verified",
|
|
||||||
"latitude",
|
|
||||||
"longitude"
|
|
||||||
], [
|
|
||||||
"AND" => [
|
|
||||||
'latitude[<>]' => [$searchbounds[0]->getLatitudeInDegrees(), $searchbounds[1]->getLatitudeInDegrees()],
|
|
||||||
'longitude[<>]' => [$searchbounds[0]->getLongitudeInDegrees(), $searchbounds[1]->getLongitudeInDegrees()],
|
|
||||||
"lastgpsfix[>]" => date("Y-m-d H:i:s", strtotime("-1 hour")),
|
|
||||||
"type" => 2
|
|
||||||
],
|
|
||||||
"LIMIT" => 100
|
|
||||||
]
|
|
||||||
);
|
|
||||||
$query = ob_get_contents();
|
|
||||||
ob_clean();
|
|
||||||
$people = $database->query($query)->fetchAll();
|
|
||||||
|
|
||||||
$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"]),
|
|
||||||
"username" => $person["username"],
|
|
||||||
"verified" => $person["verified"] == 1,
|
|
||||||
"publicid" => $person["publicid"],
|
|
||||||
"latitude" => $person["latitude"] * 1.0,
|
|
||||||
"longitude" => $person["longitude"] * 1.0
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
exitWithJson([
|
|
||||||
"status" => "OK",
|
|
||||||
"radius" => $radius,
|
|
||||||
"bounds" => [
|
|
||||||
0 => [
|
|
||||||
"latitude" => $searchbounds[0]->getLatitudeInDegrees(),
|
|
||||||
"longitude" => $searchbounds[0]->getLongitudeInDegrees()
|
|
||||||
],
|
|
||||||
1 => [
|
|
||||||
"latitude" => $searchbounds[1]->getLatitudeInDegrees(),
|
|
||||||
"longitude" => $searchbounds[1]->getLongitudeInDegrees()
|
|
||||||
],
|
|
||||||
],
|
|
||||||
"nearby" => $nearby
|
|
||||||
]);
|
|
@ -0,0 +1,63 @@
|
|||||||
|
<?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/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
$radius = 0.5;
|
||||||
|
|
||||||
|
if (!empty($VARS["radius"])) {
|
||||||
|
$radius = $VARS["radius"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$poiurl = $SETTINGS["poi"]["server"] . "?latitude=" . $VARS["latitude"] . "&longitude=" . $VARS["longitude"] . "&radius_mi=" . $radius;
|
||||||
|
|
||||||
|
foreach ($SETTINGS["poi"]["categories"] as $cat) {
|
||||||
|
$poiurl .= "&type[]=$cat";
|
||||||
|
}
|
||||||
|
|
||||||
|
$nearby = json_decode(file_get_contents($poiurl), true)["features"];
|
||||||
|
|
||||||
|
$geojson = [
|
||||||
|
"status" => "OK",
|
||||||
|
"name" => "Nearby Places",
|
||||||
|
"type" => "FeatureCollection",
|
||||||
|
"features" => []
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($SETTINGS["debug"]) {
|
||||||
|
$geojson["url"] = $poiurl;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($nearby as $n) {
|
||||||
|
$properties = [
|
||||||
|
"id" => $n["properties"]["osmid"],
|
||||||
|
"name" => $n["properties"]["name"],
|
||||||
|
"currentlife" => 0,
|
||||||
|
"maxlife" => 0,
|
||||||
|
"teamid" => null,
|
||||||
|
"ownerid" => null
|
||||||
|
];
|
||||||
|
// Update properties with game data
|
||||||
|
if ($database->has("locations", ["osmid" => $properties["id"]])) {
|
||||||
|
$gameprops = $database->get("locations", ["teamid", "ownerid", "currentlife", "maxlife"], ["osmid" => $properties["id"]]);
|
||||||
|
foreach ($gameprops as $key => $value) {
|
||||||
|
$properties[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$geojson["features"][] = [
|
||||||
|
"type" => "Feature",
|
||||||
|
"geometry" => [
|
||||||
|
"type" => "Point",
|
||||||
|
"coordinates" => [
|
||||||
|
$n["geometry"]["coordinates"][0],
|
||||||
|
$n["geometry"]["coordinates"][1],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"properties" => $properties
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
exitWithJson($geojson);
|
@ -0,0 +1,72 @@
|
|||||||
|
<?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"]);
|
||||||
|
|
||||||
|
$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);
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue