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

Last Updated : 23 Jul, 2025

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.

HTML `

GeeksforGeeks

<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>

`

Output: