Update: 2026-06-30 23:32:14
This commit is contained in:
29
backend/Admin/geofence/get_heatmap.php
Normal file
29
backend/Admin/geofence/get_heatmap.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
// Optional filter: days
|
||||
$days = filterRequest('days') ?? 7;
|
||||
|
||||
try {
|
||||
$sql = "SELECT latitude, longitude, source, created_at
|
||||
FROM passenger_opening_locations
|
||||
WHERE created_at >= DATE_SUB(NOW(), INTERVAL :days DAY)
|
||||
ORDER BY created_at DESC LIMIT 5000"; // Limit to prevent massive payloads
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->bindValue(':days', (int) $days, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
|
||||
$locations = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
echo json_encode([
|
||||
"status" => "success",
|
||||
"data" => $locations
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("Error fetching heatmap data: " . $e->getMessage());
|
||||
echo json_encode(["status" => "error", "message" => "Server error"]);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user