HTML DOM Geolocation coords.altitude Property (original) (raw)

Last Updated : 23 Nov, 2021

In this article, we will discuss the Geolocation altitude 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.altitude: This property will return the altitude in meters above the sea level.

Syntax:

coords.altitude

Example: The following HTML code will return the altitude.

HTML `

GeeksforGeeks

Displaying Altitude

<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 = "Altitude: " 
          + pos.coords.altitude;
    }
</script>

`

Output:

Supported Browsers: