I want to show the temperature from ma current location.
I have put my files on the server; unblocked the location on GoogleChrome.
I have subscribed to OpenWeatherMap and copy paste the correct apiKey and I do still have this error: Unable to fetch temperature
Here is the error message from my console log:
Unchecked runtime.lastError: The message port closed before a response was received.
GET https://api.openweathermap.org/data/2.5/weather?lat=pastenumber&lon=pastenumber&units=metric&appid=YOUR_API_KEY net::ERR_INTERNET_DISCONNECTED
Error fetching weather data: TypeError: Failed to fetch at script.js:9:34
Here is the script.js :
window.addEventListener('load', () => {
const latitude = pastenumber;
const longitude = pastenumber;
const apiKey = 'pasteNumberFromOpenWeatherMapApp';
const apiUrl = `https://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${latitude},${longitude}`;
fetch(apiUrl)
.then(response => {
if (!response.ok) {
throw new Error('Weather data not available');
}
return response.json();
})
.then(data => {
const temperature = data.current.temp_c;
console.log(`Current Temperature: ${temperature}°C`);
})
.catch(error => {
console.error('Error fetching weather data:', error);
});
});
I am expecting to get the temperature of my current location.
Thanks for your help.