Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

HTML DOM Geolocation coords.heading Property

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

In this article, we will discuss about the Geolocation coords.heading 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.

The Geolocation coords.heading property is used return the clock wise from the north in degrees. If it is not applicable, it will return null.

Syntax:

coords.heading

 

Example:

HTML




<!DOCTYPE html>
<html>
<body>
    <h2 style="color:green">
      GeeksforGeeks
      </h2>
    <p><b> Displaying heading</b></p>
  
    <button onclick="getlocation()"
      Click Me 
      </button>
    <p id="paraID"></p>
  
    
    <script>
        var variable1 = document.getElementById("paraID");
  
        function getlocation() {
            navigator
              .geolocation
              .getCurrentPosition(showLoc, error, options);
        }
  
        function showLoc(pos) {
            variable1.innerHTML = "Heading: " 
              + pos.coords.heading;
        }
        
        function error(err) {
              console.warn(
              `ERROR(${err.code}): ${err.message}`
            );
        }
        var options = {
            enableHighAccuracy: true,
            timeout: 5000,
            maximumAge: 0
        };
    </script>
</body>
</html>

Output:

Supported Browsers:

  • Google Chrome 5.0
  • Internet Explorer 9.0
  • Firefox 3.5
  • Opera 16.0
  • Safari 5.0

My Personal Notes arrow_drop_up
Last Updated : 23 Nov, 2021
Like Article
Save Article
Similar Reads
Related Tutorials