I was making weather application and i was trying to fetch data from API but i am getting CORS error again and again please help me solve this. Thank you!
//adding event lisitener to ask location
window.addEventListener("load", () => {
let long;
let lat;
//getting geolocation and current position
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
long = position.coords.longitude;
lat = position.coords.latitude;
//API for weather websites.
let api = api.openweathermap.org/data/2.5/weather?
lat=${lat}&lon=${long}&appid=b49f9f35788fbd19a06bc8d82140c40f;
//fetching data from api
fetch(api).then((response) => {
return response.json();
})
.then(data => {
const { name } = data;
const { feels } = data.main;
const { id, main } = data.weather[0];
//Manipulating DOM
loc.textContent = name;
climate.textContent = main;
tempvalue.textContent = Math.round(feels - 273);
})
})
}
});