Browse Source

Add API to get a single place using OSMID

master
Skylar Ittner 3 years ago
parent
commit
64c1611867
1 changed files with 46 additions and 0 deletions
  1. 46
    0
      place.php

+ 46
- 0
place.php View File

@@ -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;
}

Loading…
Cancel
Save