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

155
Vistas
How can i approximate latitude and longtitude in html?

How can i approximate latitude and longitude in html?
I want 4 decimal places and I want it that circled in the picture to hidden picture.jpg
Thank you very much.

This is a code

<!DOCTYPE html>
<html>

<body>

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

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

  <p id="demo"></p>
  <input type="text" id="lat" name="lat">
  <input type="text" id="lon" name="lon">

  <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;
      $("#lat").val(position.coords.latitude);
      $("#lon").val(position.coords.longitude);
    }
  </script>
  <script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
  <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
</body>

</html>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If the aim is to format the number as a string with a given precision then use the toFixed function, e.g.

var numberOfDecimals = 4;
var latitude = position.coords.latitude.toFixed(numberOfDecimals);
var longitude = position.coords.longitude.toFixed(numberOfDecimals);

If the intention is to limit the precision of the original number, then the rounding might be used:

var rounded = Math.round(value * 10000) / 10000; // leaves only 4 digits    
about 4 years ago · Juan Pablo Isaza Denunciar
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