Update terrain.php to use bounding boxes, add places.php from earth.apis.netsyms.com
parent
1b3a85b72b
commit
633ee1bf41
@ -1,13 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "vendor/g-i-s-a-p-i",
|
"name": "netsyms/gis-api",
|
||||||
"description": "Description of project GIS API.",
|
"description": "Simple PHP API for accessing earth data.",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "skylar",
|
"name": "Skylar Ittner",
|
||||||
"email": "your@email.here"
|
"email": "admin@netsyms.com",
|
||||||
|
"homepage": "https://netsyms.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"catfan/medoo": "^1.1"
|
"catfan/medoo": "^1.1",
|
||||||
|
"anthonymartin/geo-location": "^1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes the latitude and longitude and gets nearby places from OSM.
|
||||||
|
*
|
||||||
|
* Uses WGS84 in the DD.DD format, because I say so.
|
||||||
|
*/
|
||||||
|
require 'required.php';
|
||||||
|
|
||||||
|
use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation;
|
||||||
|
|
||||||
|
if (is_empty($VARS['lat'])) {
|
||||||
|
sendError("Missing required latitude (lat) variable.", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_empty($VARS['long'])) {
|
||||||
|
sendError("Missing required longitude (long) variable.", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!preg_match('/-?[0-9]{1,3}\.[0-9]{1,}/', $VARS['lat'])) {
|
||||||
|
sendError("Latitude (lat) is in the wrong format, or does not have enough precision (DD.DD, at least 2 decimal places.", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!preg_match('/-?[0-9]{1,3}\.[0-9]{1,}/', $VARS['long'])) {
|
||||||
|
sendError("Longitude (long) is in the wrong format, or does not have enough precision (DD.DD, at least 2 decimal places.", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$lat = number_format((float) $VARS['lat'], 5, '.', '');
|
||||||
|
$long = number_format((float) $VARS['long'], 5, '.', '');
|
||||||
|
|
||||||
|
$radius = 5;
|
||||||
|
if (!is_empty($VARS['radius']) && is_numeric($VARS['radius'])) {
|
||||||
|
$radius = floatval($VARS['radius']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$userlocation = GeoLocation::fromDegrees($VARS['lat'], $VARS['long']);
|
||||||
|
$searchbounds = $userlocation->boundingCoordinates($radius, 'miles');
|
||||||
|
|
||||||
|
if (is_empty($VARS['names'])) {
|
||||||
|
$places = $database->select('places', '*', ['AND' => [
|
||||||
|
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
|
||||||
|
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
|
||||||
|
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
|
||||||
|
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()],
|
||||||
|
"LIMIT" => 100
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$places = $database->select('places', '*', ['AND' => [
|
||||||
|
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
|
||||||
|
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
|
||||||
|
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
|
||||||
|
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees(),
|
||||||
|
'name[!]' => ''],
|
||||||
|
"LIMIT" => 100
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$geo['name'] = "Places";
|
||||||
|
$geo['type'] = 'FeatureCollection';
|
||||||
|
$geo['features'] = [];
|
||||||
|
|
||||||
|
foreach ($places as $place) {
|
||||||
|
$geo['features'][] = array("type" => "Feature",
|
||||||
|
"geometry" => [
|
||||||
|
"type" => "Point",
|
||||||
|
"coordinates" => [
|
||||||
|
floatval($place['longitude']),
|
||||||
|
floatval($place['latitude'])
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"properties" => [
|
||||||
|
"osm_id" => intval($place['osmid']),
|
||||||
|
"name" => ($place['name'] == '' ? null : $place['name']),
|
||||||
|
"name:en" => ($place['name'] == '' ? null : $place['name'])
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
echo json_encode($geo);
|
Loading…
Reference in New Issue