-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
80 lines (56 loc) · 2.76 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
window.addEventListener('load', ()=>{
let lon
let lat
let temperaturaValor = document.getElementById('temperatura-valor')
let temperaturaDescripcion= document.getElementById('temperatura-descripcion')
let ubicacion = document.getElementById('ubicacion')
let iconoAnimado = document.getElementById('icono-Animado')
let vientoVelocidad = document.getElementById('Viento-velocidad')
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition( posicion => {
lon = posicion.coords.longitude
lat = posicion.coords.latitude
//console.log(posicion.coords.latitude)
//const url = 'https://api.openweathermap.org/data/2.5/weather?lat=4.538507&lon=-75.676773&appid=9a135c0218a1298ae83897722aa954dc'
//console.log(url)
const url = 'https://api.openweathermap.org/data/2.5/weather?q=Quindio&lang=es&units=metric&appid=9a135c0218a1298ae83897722aa954dc'
//console.log(url)
fetch(url)
.then( Response=> { return Response.json () })
.then( data => {
let temp = Math.round (data.main.temp)
temperaturaValor.textContent = `${temp} °C`
let desc = (data.weather[0].description)
temperaturaDescripcion.textContent = desc.toUpperCase()
ubicacion.textContent = data.name
vientoVelocidad.textContent = `${data.wind.speed} m/s`
//console.log(data.wind.speed)
// para iconos estaticos
/*console.log(data.weather[0].icon)
let iconCode = data.weather[0].icon
const urlicon = `http://openweathermap.org/img/wn/${iconCode}.png`
console.log(urlicon)
*/
//iconos animados
console.log(data.weather[0].main)
switch (data.weather[0].main){
case 'Clouds':
iconoAnimado.src = 'animated/cloudy.svg'
console.log('NUBES')
break;
case 'Clear':
iconoAnimado.src = 'animated/day.svg'
console.log('LIMPIO')
break;
case 'Rain':
iconoAnimado.src = 'animated/rainy-6.svg'
console.log('Lluvia ligera')
break;
}
})
.catch(error => {
console.log(error)
})
})
}
})