-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
46 lines (38 loc) · 1.58 KB
/
Copy pathapp.js
File metadata and controls
46 lines (38 loc) · 1.58 KB
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
window.addEventListener("load", () => {
let long;
let lat;
let timezonePlace = document.querySelector(".timezone-place");
let timezonSummary = document.querySelector(".timezone-summary");
let timezoneIcon = document.querySelector(".icon");
let temp = document.querySelector(".temp");
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(position => {
console.log(position);
long = position.coords.longitude;
lat = position.coords.latitude;
const proxy = `https://cors-anywhere.herokuapp.com/`;
const secretKey = `1dbbcd96b1a5d16c890273603404692d`;
const apiKey = `${proxy}https://api.darksky.net/forecast/${secretKey}/${lat},${long}`;
fetch(apiKey)
.then(response => {
return response.json();
})
.then(data => {
console.log(data);
const timezone = data.timezone
const {temperature, summary, icon } = data.currently;
console.log(icon);
timezonePlace.textContent = timezone;
timezonSummary.textContent = `Summary:` + ` ` + summary;
temp.textContent = `Temperature:` + ` ` + temperature;
setIcons(icon, timezoneIcon);
});
});
}
function setIcons(icon, iconID) {
const skycons = new Skycons({color: "white"});
const currentIcon = icon.replace(/-/g, "_").toUpperCase();
skycons.play();
return skycons.set(iconID, Skycons[currentIcon]);
}
})