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

431
Visualizações
gps geolocation coordinate stucked in PWA js

I am facing an issue with stucked gps coordinates using geolocation in a pwa. The problem is that sometimes, the coordinates stucked in the previous location. For example I got the location of a place, the user was an hour ago.

I believe this cases I got the location of the last location the gps could track.

Is there anyway to refresh the gps, and only send the data once gps has valid, refreshed connection?

The code for geolocation:

   if ("geolocation" in navigator && navigator.geolocation != null) {
                try {
                    navigator.geolocation.getCurrentPosition(position => {
                        //if geolocation has valid connection
                        console.log(position);
                        $('#geolocation_form_latitude').val(position.coords.latitude);
                        $('#geolocation_form_longitude').val(position.coords.longitude);
                        $('#geolocation_form').submit();

                    }, error => {
                        $('#geolocation_form').submit();
                    })
                }
                catch (e) {
                    $('#geolocation_form').submit();
                }
     }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Mobile OSes routinely do this kind of cacheing for battery management - it reduces the need to power up energy-intensive radios such as GPS and WiFi. Hence most mobile browsers will also demonstrate this stale location behaviour because they are dependent on the OS's location services.

Attempt to use the options in the HTML5 geolocation API to see if it helps get a better fix. Also note that both Safari and Chrome on iOS return additional properties on the returned geolocation object as suggested in this Chrome developer documentation - I notice a key called "Cache Age" when loading this test page which may be used to verify freshness of the fix.

maximumAge Is a positive long value indicating the maximum age in milliseconds of a possible cached position that is acceptable to return. If set to 0, it means that the device cannot use a cached position and must attempt to retrieve the real current position. If set to Infinity the device must return a cached position regardless of its age. Default: 0.

enableHighAccuracy Is a boolean value that indicates the application would like to receive the best possible results. If true and if the device is able to provide a more accurate position, it will do so. Note that this can result in slower response times or increased power consumption (with a GPS chip on a mobile device for example). On the other hand, if false, the device can take the liberty to save resources by responding more quickly and/or using less power. Default: false.

about 4 years ago · Juan Pablo Isaza Relatório
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