Last active
August 9, 2019 21:53
-
-
Save parzibyte/cc5cb4be42b95c3f5025d504a30a9100 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
const funcionInit = () => { | |
if (!"geolocation" in navigator) { | |
return alert("Tu navegador no soporta el acceso a la ubicación. Intenta con otro"); | |
} | |
let idWatcher = null; | |
const onUbicacionConcedida = ubicacion => { | |
console.log(ubicacion); | |
} | |
const onErrorDeUbicacion = err => { | |
console.log("Error obteniendo ubicación: ", err); | |
} | |
const detenerWatcher = () => { | |
if (idWatcher) { | |
navigator.geolocation.clearWatch(idWatcher); | |
idWatcher = null; | |
} | |
} | |
const opcionesDeSolicitud = { | |
enableHighAccuracy: true, // Alta precisión | |
maximumAge: 0, // No queremos caché | |
timeout: 5000 // Esperar solo 5 segundos | |
}; | |
idWatcher = navigator.geolocation.watchPosition(onUbicacionConcedida, onErrorDeUbicacion, opcionesDeSolicitud); | |
}; | |
document.addEventListener("DOMContentLoaded", funcionInit); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment