Latitude and Longitude in a form

Hi !
How to get the lat/long of a user and embed it in a hiden field of a form ???

  1. include a javascript in a custom code inside your page.
    This one I figured :
<script>
document.addEventListener('DOMContentLoaded', function() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position) {
            const lat = position.coords.latitude;
            const lon = position.coords.longitude;

            // Set the latitude and longitude to hidden fields
            document.getElementById('hiddenLatField').value = lat;
            document.getElementById('hiddenLonField').value = lon;
        }, function(error) {
            console.error('Error obtaining location:', error);
        });
    } else {
        console.error('Geolocation is not supported by this browser.');
    }
});
</script>
  1. But then… how to pass thoses two data (lat/long) into a hidden form in Softr ??? (I use a button to open a modal with a form)

Hi @alx2bgx I used that kind of script, but finally I changed to a Fillout Form for that… so I get coord. and after that I divide them in Airtable, with LEFT and RIGH formulas… but take into account that I prefer that the user/worker… knows that they are gonna send them


1 Like

Hi Alex,

1 Like

Thank you so much Mathieu. (A little bit late in my answer !!!)

1 Like