Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML DOM Geolocation coords.accuracy Property

  • Last Updated : 11 Nov, 2021

In this article, we will discuss the Geolocation accuracy property. Geolocation in HTML  is used to get the geographical position of a user. The getCurrentPosition() method in this geolocation returns an object on success.

HTML Geolocation coords.accuracy Property: This property will return the accuracy of the location as a decimal number

Syntax:

coords.accuracy

Example: The following HTML program returns the accuracy.

HTML




<!DOCTYPE html>
<html>
<body>
    <h2 style="color:green">
        GeeksforGeeks
    </h2>
  
    <p><b>Displaying Accuracy</b></p>
  
    <button onclick="getlocation()"
        Click Me 
    </button>
  
    <p id="paraID"></p>
  
    <script>
        var variable1 = document.getElementById("paraID");
  
        function getlocation() {
            navigator.geolocation.getCurrentPosition(showLoc);
        }
  
        function showLoc(pos) {
            variable1.innerHTML = "Accuracy: "
                + pos.coords.accuracy;
        }
    </script>
</body>
  
</html>

Output:

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!