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

171
Vistas
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 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