Files
tugas-kuliah-SIG/Tugas_2_SIG/get_spbu.php
T
Wilhelmus Ikchan Dwi Putra c8e75593cb Upload semua tugas SIG
2026-06-13 00:45:23 +07:00

27 lines
755 B
PHP

<?php
// get_spbu.php
header('Content-Type: application/json');
$conn = new mysqli("localhost", "root", "", "db_tugas_1_sig"); // sesuaikan dengan database kamu
$response = [];
$result = $conn->query("SELECT * FROM data_spbu");
while($row = $result->fetch_assoc()) {
$geo = json_decode($row['geojson'], true);
// Ekstrak koordinat Longitude dan Latitude dari objek GeoJSON Point
$lng = $geo['geometry']['coordinates'][0];
$lat = $geo['geometry']['coordinates'][1];
$response[] = [
'id' => $row['id'],
'nama' => $row['nama_spbu'],
'status_24jam' => $row['status_24jam'],
'alamat' => $row['alamat'],
'lat' => $lat,
'lng' => $lng
];
}
echo json_encode($response);
$conn->close();
?>