Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
How to call geolocation.getCurrentPosition() without having to give permission every time?

Here's a stripped-down version of a script that displays position information every 5 seconds:

<script>
    var showPositionError = function(error) {
        document.getElementById("message").innerHTML = "Error:  " + error.message
    }
    var showPosition = function(position) {
        console.log(Date(), position.coords.latitude)
    }
    var loop = function() {
        navigator.geolocation.getCurrentPosition(showPosition, showPositionError)
    }
    setInterval(loop, 5*1000)
</script>

It works, but the alert asking me to block or allow the query appears with every iteration.

If I delay answering for a while, it continues iterating, and when I finally do respond all pending queries happen at the same time (the line with 8 repetitions):

  pos2.html:17 Mon Jul 18 2022 16:47:56 GMT-0400 (Eastern Daylight Time) 43.4470912  
  pos2.html:17 Mon Jul 18 2022 16:48:01 GMT-0400 (Eastern Daylight Time) 43.4470912  
  pos2.html:17 Mon Jul 18 2022 16:48:06 GMT-0400 (Eastern Daylight Time) 43.4470912  
8 pos2.html:17 Mon Jul 18 2022 16:48:49 GMT-0400 (Eastern Daylight Time) 43.4470912  
  pos2.html:17 Mon Jul 18 2022 16:48:52 GMT-0400 (Eastern Daylight Time) 43.4470912  
  pos2.html:17 Mon Jul 18 2022 16:48:56 GMT-0400 (Eastern Daylight Time) 43.4470912

This is using Chrome on Ubuntu 20.04.

There's obviously something I'm not understanding about how these mechanisms work.

What do I need to do so that it will ask for permission only the first time?

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda