Skip to content
Related Articles
Open in App
Not now

Related Articles

HTML DOM Geolocation coords.longitude Property

Improve Article
Save Article
  • Last Updated : 15 Nov, 2021
Improve Article
Save Article

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




Example: The following HTML program returns the longitude.


<!DOCTYPE html>
    <h2 style="color:green">
    <p><b> Displaying location using longitude</b></p>
    <button onclick="getlocation()">
        Click Me
    <p id="paraID"></p>
        var variable1 = document.getElementById("paraID");
        function getlocation() {
        function showLoc(pos) {
            variable1.innerHTML =
                "Longitude: " + pos.coords.longitude;


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!