MCPcopy Create free account
hub / github.com/AyushSaini00/60minuteJavaScript / getWeather

Function getWeather

Weather-app/app.js:46–65  ·  view source on GitHub ↗
(myLat, myLong)

Source from the content-addressed store, hash-verified

44//GET WEATHER
45
46function getWeather(myLat, myLong){
47 let link = `${myApi.proxy}https://api.openweathermap.org/data/2.5/weather?lat=${myLat}&lon=${myLong}&appid=${myApi.key}`;
48 fetch(link) //send a network request and get the information from the server
49 .then(response => {
50 let data = response.json(); //now whatever response we get, parse it into json and store in data
51 return data;
52 })
53 .then(data => { //then we update our weather object with the required data
54 // console.log(data);
55 weather.temperature.value = Math.floor(data.main.temp - KELVIN);
56 weather.description = data.weather[0].description;
57 weather.iconID = data.weather[0].icon;
58 weather.city = data.name;
59 weather.country = data.sys.country;
60 weather.humidity = data.main.humidity;
61 })
62 .then(() => { //then display the weather to the ui
63 displayWeather();
64 });
65}
66
67//DISPLAYING THE WEATHER TO THE UI
68function displayWeather() {

Callers 1

setPositionFunction · 0.85

Calls 1

displayWeatherFunction · 0.85

Tested by

no test coverage detected