Upload files to "/"
This commit is contained in:
53
weather.html
Normal file
53
weather.html
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>NOAA Weather App</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Current Weather</h1>
|
||||||
|
<div id="location">Loading...</div>
|
||||||
|
<div id="weather"></div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const fallbackCoords = { lat: 38.8977, lon: -77.0365 }; // Washington, D.C.
|
||||||
|
|
||||||
|
function getWeather(lat, lon) {
|
||||||
|
fetch(`https://api.weather.gov/points/${lat},${lon}`)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
const city = data.properties.relativeLocation.properties.city;
|
||||||
|
const state = data.properties.relativeLocation.properties.state;
|
||||||
|
const forecastUrl = data.properties.forecast;
|
||||||
|
|
||||||
|
document.getElementById('location').innerText = `Location: ${city}, ${state}`;
|
||||||
|
|
||||||
|
// Get forecast
|
||||||
|
return fetch(forecastUrl);
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(forecastData => {
|
||||||
|
const period = forecastData.properties.periods[0];
|
||||||
|
document.getElementById('weather').innerHTML = `
|
||||||
|
<strong>${period.name}:</strong> ${period.temperature}°${period.temperatureUnit}, ${period.shortForecast}
|
||||||
|
`;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
document.getElementById('location').innerText = 'Failed to load weather.';
|
||||||
|
console.error('Error fetching NOAA weather:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get user location or fallback
|
||||||
|
if (navigator.geolocation) {
|
||||||
|
navigator.geolocation.getCurrentPosition(
|
||||||
|
pos => getWeather(pos.coords.latitude, pos.coords.longitude),
|
||||||
|
() => getWeather(fallbackCoords.lat, fallbackCoords.lon)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
getWeather(fallbackCoords.lat, fallbackCoords.lon);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user