Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!