This is my first time working with an API. It will be part of a bigger practice project, but I'm a bit stuck. First, I want my code to geolocate the user, get the altitude and longitude, than using that make a call to the OpenWeather API and console log the temperature, humidity and the description. My problem seems to be that my link is not working... can anyone help me explain what am I doing wrong? (The Api key is deleted here)
/*Geolocation*/
let latUser = []
let lonUser = []
const errorCallback = (error) => {console.error(error)}
const successCallback = (position) => {
latUser.push(position.coords.latitude)
lonUser.push(position.coords.longitude)}
navigator.geolocation.getCurrentPosition(successCallback, errorCallback)
/*Weather*/
let weather = {
"apiKey": "xxx",
fetchWeather: function () {
fetch("api.openweathermap.org/data/2.5/weather?lat=" + latUser[0] + "&lon=" + lonUser[0] +
"&appid=" + this.apiKey
).then((response) => response.json())
.then((data) => this.displayWeather(data))
},
displayWeather: function(data){
const { temp, humidity } = data.main
const { description } = data.weather
console.log (temp, humidity, description)
}
}