Open In App

HTML DOM Geolocation coords.latitude Property

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will discuss the Geolocation latitude 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.latitude: This property will return the latitude as a decimal number.

Please refer to the HTML Geolocation article for further details about the other location properties.
 

Syntax:

coords.latitude

Return Value:- This property returns the latitude as a decimal number.

Example: The following HTML code will return the latitude.

 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <meta charset="utf-8">
    <meta name="viewport" content=
        "width=device-width,initial-scale=1">
</head>
 
<body>
    <h2 style="color:green">
        GeeksforGeeks
    </h2>
     
     
<p>
        <b>Displaying location using latitude</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 = "Latitude: "
                + pos.coords.latitude;
        }
    </script>
</body>
 
</html>


Output:

Supported Browsers:

  • Google Chrome
  • Microsoft Edge
  • Firefox
  • Opera
  • Safari


Last Updated : 20 Nov, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads