Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 9, 2018 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/687fd25d87b84b285b8e16a801b55df2 to your computer and use it in GitHub Desktop.
Save parzibyte/687fd25d87b84b285b8e16a801b55df2 to your computer and use it in GitHub Desktop.
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