Add location storage to database, add getnearby API to find receivers
This commit is contained in:
parent
d1fced61ea
commit
11b61a7125
74
api/actions/nearby.php
Normal file
74
api/actions/nearby.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?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 = 0.25;
|
||||
if (!empty($VARS["radius"])) {
|
||||
$radius = min(10, $VARS["radius"] * 1.0);
|
||||
}
|
||||
$searchbounds = $userlocation->boundingCoordinates($radius, "miles");
|
||||
|
||||
// (NPR voice): The following horrible workaround is brought to you by:
|
||||
// Medoo bugs #797, #828, member stations, and viewers like you
|
||||
ob_end_flush();
|
||||
ob_start();
|
||||
$people = $database->debug()->select("accounts", [
|
||||
"publicid",
|
||||
"name",
|
||||
"username",
|
||||
"verified",
|
||||
"latitude",
|
||||
"longitude"
|
||||
], [
|
||||
"AND" => [
|
||||
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
|
||||
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
|
||||
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
|
||||
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees(),
|
||||
"lastgpsfix[>]" => date("Y-m-d H:i:s", strtotime("-1 hour")),
|
||||
"type" => 2
|
||||
],
|
||||
"LIMIT" => 20
|
||||
]
|
||||
);
|
||||
$people = $database->query(ob_get_contents())->fetchAll();
|
||||
ob_end_clean();
|
||||
// No more really bad code allowed past this point
|
||||
|
||||
|
||||
$nearby = [];
|
||||
|
||||
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
|
||||
]);
|
@ -65,5 +65,14 @@ $APIS = [
|
||||
"key" => $keyregex,
|
||||
"id (optional)" => "/[0-9a-z]+/"
|
||||
]
|
||||
],
|
||||
"getnearby" => [
|
||||
"load" => "nearby.php",
|
||||
"vars" => [
|
||||
"key" => $keyregex,
|
||||
"latitude" => "/-?[0-9]{2}\.[0-9]+/",
|
||||
"longitude" => "/-?[0-9]{2,3}\.[0-9]+/",
|
||||
"radius (optional)" => "/[0-9]*\.?[0-9]+/"
|
||||
]
|
||||
],
|
||||
];
|
||||
|
@ -4,7 +4,8 @@
|
||||
"type": "project",
|
||||
"require": {
|
||||
"catfan/medoo": "^1.5",
|
||||
"guzzlehttp/guzzle": "^6.2"
|
||||
"guzzlehttp/guzzle": "^6.2",
|
||||
"anthonymartin/geo-location": "^1.0"
|
||||
},
|
||||
"license": "MPL-2.0",
|
||||
"authors": [
|
||||
|
47
composer.lock
generated
47
composer.lock
generated
@ -4,8 +4,53 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "e4e700119f47d2f68b0ed82abaf8c5c6",
|
||||
"content-hash": "a4330dce069db4d0d962b670496ca8ef",
|
||||
"packages": [
|
||||
{
|
||||
"name": "anthonymartin/geo-location",
|
||||
"version": "v1.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/anthonymartin/GeoLocation.php.git",
|
||||
"reference": "50bf026f069296dfae11aa195d987854b2e75855"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/anthonymartin/GeoLocation.php/zipball/50bf026f069296dfae11aa195d987854b2e75855",
|
||||
"reference": "50bf026f069296dfae11aa195d987854b2e75855",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"type": "class",
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"AnthonyMartin": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"CC 3.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Anthony Martin",
|
||||
"email": "anthony@replaycreative.com",
|
||||
"homepage": "http://replaycreative.com",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Retrieve bounding coordinates, distances, longitude and latitude with GeoLocation.class.php",
|
||||
"homepage": "https://github.com/anthonymartin/GeoLocation.php",
|
||||
"keywords": [
|
||||
"bounding coordinates",
|
||||
"distances",
|
||||
"geocoding",
|
||||
"geolocation"
|
||||
],
|
||||
"time": "2016-09-17T18:05:14+00:00"
|
||||
},
|
||||
{
|
||||
"name": "catfan/medoo",
|
||||
"version": "v1.6.1",
|
||||
|
BIN
database.mwb
BIN
database.mwb
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user