Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active August 9, 2019 21:53
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/cc5cb4be42b95c3f5025d504a30a9100 to your computer and use it in GitHub Desktop.
Save parzibyte/cc5cb4be42b95c3f5025d504a30a9100 to your computer and use it in GitHub Desktop.
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