'failure', 'message' => 'Unauthorized']); exit; } try { $countryCode = filterRequest('country_code'); if (!$countryCode) { $countryCode = 'SY'; // Fallback } $surgeKey = "surge:opportunities:{$countryCode}"; $hotspotsJson = $redis->get($surgeKey); $hotspots = $hotspotsJson ? json_decode($hotspotsJson, true) : []; $driverHeatmap = []; if (!empty($hotspots)) { foreach ($hotspots as $grid => $multiplier) { // Only show grids with a meaningful multiplier > 1.05 if ($multiplier > 1.05) { list($lat, $lng) = explode('_', $grid); $driverHeatmap[] = [ 'lat' => (float)$lat, 'lng' => (float)$lng, 'surge_multiplier' => (float)$multiplier, 'radius_meters' => 1500 // 1.5km grid box ]; } } } jsonSuccess([ 'status' => 'success', 'message' => 'Surge heatmap data fetched', 'hotspots' => $driverHeatmap ]); } catch (Exception $e) { error_log("[get_surge_heatmap] Error: " . $e->getMessage()); jsonError("Failed to fetch heatmap"); }