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

185
Visualizações
Javascript, cannot find variable for if statement using coordinates from Geolocation API to cause an event

I am using Geolocation API to find a user's coordinates, and then based on those coordinates redirecting them to the appropriate webpage based on their coordinates. But I am struggling set up the if-statement that will redirect to another webpage. What is the variable that will cause the if-statement to redirect to the user to the correct page?

<button onclick="getLocation()">Get Location</button>
  <p id="demo"></p>

  <script>
  var x = document.getElementById("demo");

  function getLocation() {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(showPosition);
    } else {
      x.innerHTML = "Geolocation is not supported by this browser.";
    }
  }

  function showPosition(position) {
  x.innerHTML = "Latitude: " + position.coords.latitude +
  "<br>Longitude: " + position.coords.longitude;

  if (showPosition(latitude) > 34) {
      console.log("It worked");
  }
}
</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

the problem is that you used showPosition(latitude) which is the function name instead of the parameter position which holds the coordinates data

if (position.coords.latitude > 34) {
   console.log("It worked");
}
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