Forums

latitude / longitude data

daddyp 09 Oct, 2023
Hello, i must save latitude and longitude data on db.
I obtain the data from the script, but i'm not able to save data on db.

<!DOCTYPE html>
<html>
<body>

<body onload="getLocation()">
<p id="demo"></p>

<script>
var x = document.getElementById("demo");

function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
    document.getElementsByName('lat')[0].value = position.coords.latitude;
    document.getElementsByName('lng')[0].value = position.coords.longtitude;
  } else { 
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}
    
function showPosition(position) {
  x.innerHTML = "Latitude: " + position.coords.latitude + 
  "<br>Longitude: " + position.coords.longitude +
  "<br>Precisione: " + position.coords.accuracy;
}
</script>

</body>
</html>


Anyone can help me?

Thanks
Max_admin 11 Oct, 2023
Answer
if you are able to set the value of 2 hidden form fields to lat and lang then save the form then it should be stored.

you can check if the fields are set using the browser's console
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
You need to login to be able to post a reply.