Add API to get a single place using OSMID
부모
93b99f8282
커밋
64c1611867
@ -0,0 +1,46 @@
|
||||
<?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['osmid'])) {
|
||||
sendError("Missing OSMID.", true);
|
||||
}
|
||||
|
||||
$radius = 5;
|
||||
if (!is_empty($VARS['radius']) && is_numeric($VARS['radius'])) {
|
||||
$radius = floatval($VARS['radius']);
|
||||
}
|
||||
|
||||
$place = $database->select('places', '*', ['osmid' => $VARS['osmid']])[0];
|
||||
|
||||
$geo['name'] = "Places";
|
||||
$geo['type'] = 'FeatureCollection';
|
||||
$geo['features'] = [];
|
||||
|
||||
$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'])
|
||||
]
|
||||
);
|
||||
|
||||
$out = json_encode($geo);
|
||||
if ($out == false) {
|
||||
sendError("Server error.");
|
||||
} else {
|
||||
echo $out;
|
||||
}
|
불러오는 중...
Reference in New Issue