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

162
Visualizações
Is there a simple function to return North or South hemisphere depending on response from browser Geolocation API in JavaScript?

<p>Click the button to get your coordinates.</p>

<button onclick="getLocation()">Try It</button>

<p id="demo"></p>

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

function getLocation() {
  try {
    navigator.geolocation.getCurrentPosition(showPosition);
  } catch {
    x.innerHTML = err;
  }
}

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

I'm new to the JavaScript Geolocation API. So far it is very useful. However, I am trying to write some JavaScript that will calculate a price depending on what hemisphere you are in. North or South. So far I am using DEMO to return and display the latitude and longitude. I'm having trouble passing the response or that variable to another function. The goal is to recieve the Latitude and perform a simple calculation.

response would be equal to demo if demo > 0.00 then return northernHemisphere if demo < 0.00 then return southernHemisphere

The next goal would be to perform a very simple calculation on northernHemisphere and southernHemisphere.

If you are in northernHemisphere I want to display text or variable that it will cost $10 in shipping. If you are in the southernHemisphere I just want to return text that shipping will cost $20.

I'm sure there are way better and real shipping cost calculators but that's not the goal here. My goal is to return either north or south and display text of $10 or $20. Not looking for more accurate or complicity, just trying to learn basics of javascript variables and functions.

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