Created
March 9, 2018 23:13
-
-
Save parzibyte/687fd25d87b84b285b8e16a801b55df2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pedirUbicacion() { | |
if("geolocation" in navigator){ | |
navigator.geolocation.getCurrentPosition( | |
ubicacion =>{ | |
let coordenadas = ubicacion.coords; | |
this.cargandoClima = true; | |
fetch(`https://fcc-weather-api.glitch.me/api/current?lat=${coordenadas.latitude}&lon=${coordenadas.longitude}`) | |
.then(respuesta => { | |
return respuesta.json(); | |
}) | |
.then(datosClima => { | |
this.clima = datosClima; | |
this.dialogo = true; | |
console.log(datosClima); | |
}) | |
.finally(() => { | |
this.cargandoClima = false; | |
}); | |
}, | |
() => { | |
alert("No pude obtener tu ubicación. Intenta más tarde.") | |
}, | |
{ | |
enableHighAccuracy: true, | |
} | |
); | |
}else alert("Lo siento, tu navegador no tiene soporte para obtener tu ubicación") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment