Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

HTML | Navigator geolocation Property

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The Navigator geolocation property is used to return a geolocation object by the browser which can be used to locate a user’s position. 
It is a read-only property and is only available on the approval of the user since it can compromise the user’s privacy.



Below program illustrates the Navigator geolocation Property :
Checking the user’s geolocation. 


<!DOCTYPE html>
    <title>Navigator geolocation Property in HTML</title>
        h1 {
            color: green;
        h2 {
            font-family: Impact;
        body {
            text-align: center;
    <h2>Navigator geolocation Property</h2>
<p>For checking your coordinates,
      double click the "Get Coordinates" button : </p>
    <button ondblclick="getCoordinates()">Get Coordinates</button>
    <p id="loc"></p>
        var x = document.getElementById("loc");
        function getCoordinates() {
            if (navigator.geolocation) {
            } else {
                x.innerHTML = "The browser doesn't support Geolocation.";
        function showcoordinates(myposition) {
            x.innerHTML = "Your Latitude is: " + myposition.coords.latitude +
                "<br>Your Longitude is: " + myposition.coords.longitude;

Before clicking the button:

After clicking the button: 

Supported Browsers: The browser supported by Navigator geolocation are listed below:  

  • Google Chrome 5
  • Edge 12
  • Internet Explorer 9
  • Firefox 3.5
  • Opera 10.6
  • Safari 5

My Personal Notes arrow_drop_up
Last Updated : 10 Aug, 2022
Like Article
Save Article
Similar Reads
Related Tutorials