First commit / commit pertama
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* api/fasilitas.php — GeoJSON fasilitas publik (untuk peta & proximity).
|
||||
* GET → FeatureCollection titik fasilitas (sekolah/puskesmas/pasar/dll).
|
||||
*/
|
||||
require_once __DIR__ . '/../config/db.php';
|
||||
require_once __DIR__ . '/helpers.php';
|
||||
|
||||
$pdo = Database::getConnection();
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'GET') sendError('Method not allowed', 405);
|
||||
|
||||
$stmt = $pdo->query("SELECT id, nama, jenis, ST_AsGeoJSON(geom) AS geojson FROM fasilitas_publik ORDER BY jenis, nama");
|
||||
$features = [];
|
||||
while ($r = $stmt->fetch()) {
|
||||
$features[] = [
|
||||
'type' => 'Feature',
|
||||
'geometry' => json_decode($r['geojson']),
|
||||
'properties' => ['id' => (int)$r['id'], 'nama' => $r['nama'], 'jenis' => $r['jenis']],
|
||||
];
|
||||
}
|
||||
sendSuccess(['type' => 'FeatureCollection', 'features' => $features], 'Fasilitas Publik');
|
||||
Reference in New Issue
Block a user