<?php
header('Content-Type: application/json');

require __DIR__ . '/koneksi.php';

$data = [];

$sql = "
    SELECT 
        id,
        nama_site AS name,
        lat AS latitude,
        lon AS longitude
    FROM sites
    WHERE lat IS NOT NULL
      AND lon IS NOT NULL
";

$result = $conn->query($sql);

if ($result) {
    while ($row = $result->fetch_assoc()) {
        $data[] = $row;
    }
}

echo json_encode($data);
exit;
