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

Related Articles

HTML | DOM Geolocation position Property

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

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

Return Value:

  • position.coords: The coordinates object that has all the information of the current location.
  • position.timestamp: It represents the DOMTimeStamp which represents the time when the location is obtained.

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



<!DOCTYPE html>
    DOM Geolocation position Property
    <h1 style = "color: green">
        DOM Geolocation position Property
        Click the button to get your position.
    <button onclick = "getLocation()">
        Get Location
    <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) {
            x.innerHTML = "Latitude: " +
            /* Get the latitude from the Coordinates object */
            position.coords.latitude +
            "<br>Longitude: " +
            /* Get the longitude from the Coordinates object */
            position.coords.longitude +
            "<br>Timestamp: " +
            /* Get the timestamp of the location obtained */

Output: Before Click on the button:


After Click on the button:


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

  • Google Chrome 79.0 and above
  • Edge 79.0 and above
  • Internet Explorer 9.0
  • Firefox 72.0 and above 
  • Opera 16.0 and above
  • Safari 13.1 and above

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