-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (26 loc) · 1.22 KB
/
script.js
File metadata and controls
30 lines (26 loc) · 1.22 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
window.addEventListener('load', () => {
let lon;
let lat;
const city = document.getElementById('city');
const degree = document.getElementById('degree')
const summary = document.getElementById('summary')
const icon = document.getElementById('icon')
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
lon = position.coords.longitude;
lat = position.coords.latitude;
//openweather api key
let key = '9a4aa4da44c72132f455fafa96b4a94e'
const api = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&units=metric&lang=pt_br&appid=${key}`
fetch(api)
.then(response => response.json())
.then(data => {
city.textContent = data.name;
degree.textContent = `${data.main.temp} °C`;
summary.textContent = data.weather[0].description;
icon.src = `http://openweathermap.org/img/wn/${data.weather[0].icon}@2x.png`
console.log(`http://openweathermap.org/img/wn/${data.weather[0].icon}@2x.png`)
})
})
}
})