Skip to content
Related Articles

Related Articles

Improve Article
HTML | Navigator geolocation Property
  • Last Updated : 26 Jul, 2019

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 coordiates, 
      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;


After clicking the button

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

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

My Personal Notes arrow_drop_up
Recommended Articles
Page :