-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
53 lines (39 loc) · 1.75 KB
/
app.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
window.addEventListener('load', () => {
let long;
let lat;
let temperatureDescription = document.querySelector('.temperature-description');
let temperatureDegree = document.querySelector('.temperature-degree');
let locationTimezone = document.querySelector('.location-timezone');
let locationIcon = document.querySelector('.weather-icon');
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
long = position.coords.longitude;
lat = position.coords.latitude;
const proxy = `http://cors-anywhere.herokuapp.com/`;
const api = `${proxy}https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${long}&units=metric&appid=b86fd8f7708187a762619d1377a88ec7`;
fetch(api)
.then(response => {
return response.json();
})
.then(data => {
console.log(data);
const {
feels_like
} = data.main;
const {
description
} = data.weather[0];
const {
icon
} = data.weather[0];
// const icn = `http://openweathermap.org/img/wn//${icon}@2x.png`;
//Set DOM elements from the API
temperatureDegree.textContent = feels_like;
temperatureDescription.textContent = description;
locationTimezone.textContent = data.name;
locationIcon.innerHTML = `<img src="icons/${icon}.png">`;
// locationIcon.textContent = icn;
});
});
}
});