forked from CrSandr8/TheAiTimes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.js
38 lines (35 loc) · 1.01 KB
/
weather.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Widget per il meteo, che richiede la posizione quando si accede per la prima volta nella sessione al sito
$(document).ready(() => {
let weatherData = "";
const updateWeather = (data) => {
$.ajax({
url: "/weather",
method: "POST",
data: JSON.stringify(data),
contentType: "application/json",
success: function (response) {
weatherData = response;
$("#weather").html(weatherData);
},
error: function (error) {
console.error("Error fetching weather data:", error);
},
});
};
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
async (position) => {
const data = {
lat: position.coords.latitude,
lon: position.coords.longitude,
};
updateWeather(data);
},
(error) => {
console.error("Geolocation Error:", error);
}
);
} else {
console.error("Geolocation not supported by this browser.");
}
});