The Navigator.geolocation read-only property returns a Geolocation object that gives Web content access to the location of the device. This allows a website or app to offer customized results based on the user's location.

Source : Documentation

The Geolocation.getCurrentPosition() method is used to get the current position of the device.

Source : Documentation
Info
Warning alert!, Not all devices or browsers are fully supported.

The following is an example of the program code

<script>// navigator.geolocation

var getLocation = () => {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(getPosition);
      // The Geolocation.getCurrentPosition() method is used to get the current position of the device.
    } else {
      // Section showing error or incompatible browser.
    }
  },
  getPosition = (position) => {
    let latitude = "Latitude: " + position.coords.latitude; // Get position coords latitude
    let longitude = "Longitude: " + position.coords.longitude; // Get position coords longitude
    let accuracy = "Accuracy: " + position.coords.accuracy; // Get position coords accuracy

    console.log(latitude); // Display in Console.log
    console.log(longitude); // Display in Console.log
    console.log(accuracy); // Display in Console.log
  };
getLocation();

// [open-source] : location:github.com/tamddk/library/tree/main/getGeoLocation
</script>