34935-vm/api/weather_alerts.php
Flatlogic Bot 88f77eda28 Alerts
2025-10-14 02:54:24 +00:00

45 lines
1.1 KiB
PHP

<?php
require_once __DIR__ . '/../config.php';
header('Content-Type: application/json');
// Define a sample polygon (bounding box for the US)
$location = [
'type' => 'Polygon',
'coordinates' => [
[
[-125.0, 24.0],
[-66.0, 24.0],
[-66.0, 49.0],
[-125.0, 49.0],
[-125.0, 24.0]
]
]
];
$locationJson = json_encode($location);
$apiKey = defined('OWM_API_KEY') ? OWM_API_KEY : '';
if (empty($apiKey)) {
echo json_encode(['error' => 'OpenWeatherMap API key not configured.']);
exit;
}
$url = 'https://api.openweathermap.org/data/3.0/alerts?location=' . urlencode($locationJson) . '&appid=' . $apiKey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'FlatlogicCesiumApp');
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpcode !== 200) {
echo json_encode(['error' => 'Failed to fetch weather alerts.', 'http_code' => $httpcode, 'response' => $response]);
exit;
}
echo $response;
?>