In this article, we will discuss the Geolocation longitude 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.
coords.longitude: This property will return the longitude as a decimal number
Syntax:
coords.longitude
Example: The following HTML program returns the longitude.
<!DOCTYPE html>
<html>
<body>
<h2 style="color:green">
GeeksforGeeks
</h2>
<p><b> Displaying location using longitude</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 =
"Longitude: " + pos.coords.longitude;
}
</script>
</body>
</html>
Output:
