30 lines
873 B
PHP
30 lines
873 B
PHP
<?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"]);
|
|
}
|
|
?>
|