Open In App
Related Articles

HTML DOM Geolocation coordinates Property

Improve Article
Save Article
Like Article

The DOM Geolocation coordinates Property in HTML is used to return the position and altitude of the device on Earth. The returned Coordinates object could be used for various purposes including navigation and tracking the position of the device. 

Property Values:

Values Description
coordinates.latitude This is the device latitude in decimal degrees.
coordinates.longitude This is the device longitude in decimal degrees.
coordinates.accuracy This is the accuracy of the latitude and longitude returned in meters.
coordinates.altitude This is the device altitude relative to the sea level in meters.
coordinates.altitudeAccuracy This is the accuracy of the altitude returned in meters.
coordinates.heading This is the direction in which the device is traveling. The value is in degrees and indicates the current direction with respect to true north. This value may be null.
coordinates.speed This is the velocity of the device in meters per second. The value may be null if the device is not traveling.

Usage: Methods like getCurrentPosition() or watchPosition() are used to pass a callback to a function and then access the coordinates property. 



<!DOCTYPE html>
<title>DOM Geolocation coordinates Property</title>
  <h1 style="color: green">GeeksforGeeks</h1>
  <b>DOM Geolocation coordinates Property</b>
  <p>Click the button to get your coordinates.</p>
  <button onclick="getLocation()">Get Location</button>
  <p class="location"></p>
        let x = document.querySelector('.location');
        function getLocation() {
            /* Check if location support is available */
            if (navigator.geolocation) {
                /* Callback to the showPosition function */
            } else {
                x.innerHTML = "Geolocation is not supported.";
        function showPosition(position) {
            /* Assign the Coordinates object to a variable */
            let coordinatesObject = position.coords;
            x.innerHTML =
                "Accuracy: " +
                /* Get the accuracy from the 
                Coordinates object */
                coordinatesObject.accuracy +
                "<br>Latitude: " +
                /* Get the latitude from the 
                Coordinates object */
                coordinatesObject.latitude +
                "<br>Longitude: " +
                /* Get the longitude from the 
                Coordinates object */
                coordinatesObject.longitude +
                "<br>Altitude: " +
                /* Get the altitude from the 
                Coordinates object */
                coordinatesObject.altitude +
                "<br>Altitude Accuracy: " +
                /* Get the altitude accuracy 
                from the Coordinates object */
                coordinatesObject.altitudeAccuracy +
                "<br>Speed: " +
                /* Get the speed from 
                the Coordinates object */
                coordinatesObject.speed +
                "<br>Heading: " +
                /* Get the heading from 
                the Coordinates object */

Output: Before clicking the button:


After clicking the button:


Supported Browsers: The browser supported by DOM Geolocation coordinates property are listed below:

  • Google Chrome 79 and above
  • Edge 79 and above
  • Firefox 72 and above
  • Internet Explorer 9.0 and above
  • Opera 16 and above
  • Safari 13.1 and above

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 14 Jun, 2023
Like Article
Save Article
Similar Reads
Related Tutorials