Hi alhakimyyes,
Refer below code. Make sure location services turned on your device.
Also make sure location service turned on for the browser you are checking.
JavaScript
navigator.geolocation.getCurrentPosition(
    function (position) {
        document.getElementById("txtLat").value = position.coords.latitude;
        document.getElementById("txtLon").value = position.coords.longitude;
    },
    function (error) {
        alert(error.code + ": " + error.message);
    },
    {
        enableHighAccuracy: true,
        maximumAge: 10000,
        timeout: 5000
    }
);