Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

235
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda