HTML DOM Geolocation coords.heading Property
Last Updated :
23 Nov, 2021
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...