How to get GPS location?

How can I save GPS location when I press Submit in Add page.Purpose; I would like to save device location for security purposes whenever a record is added.I have two fields in the table: Latitude and Longitude (Field Type, Decimal)

function success(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
$("#x_Latitude").val(latitude);
$("#x_Longitude").val(longitude);
};

function error() {
$("#x_Latitude").val("");
$("#x_Longitude").val("");
};
navigator.geolocation.getCurrentPosition(success, error);

The Code is not working. Reply blank.Thank you!

Assume you’re using v2020, then try to put the following code in “Row_Rendered” server event of your current table:

if (CurrentPageID() == "add" || CurrentPageID() == "edit") {
$this->Latitude->EditAttrs["onclick"] = "ew.vars.getLocation();";
$this->Longitude->EditAttrs["onclick"] = "ew.vars.getLocation();";
}

Next step, put the following code in “Client Script” section under this location: “Client Scripts” → “Table-Specific” → “Add/Copy Page” and/or “Edit Page”:

ew.vars.getLocation = function() {
  if (navigator.geolocation) {
	navigator.geolocation.getCurrentPosition(showPosition);
  } else { 
	alert("Geolocation is not supported by this browser.");
  }
}

function showPosition(position) {
  $("#x_Latitude").val( position.coords.latitude);
  $("#x_Longitude").val(position.coords.longitude);
}

After that, re-generate ALL the script files again, run the generated web app via browser, go to “Add Page” or “Edit Page”, and click on “Latitude” or “Longitude” textbox.// Credits given to: w3schools.com/html/html5_geolocation.asp

Latitude and Longitude - Field Type, Decimal? or float?

I am using MySQL, both fields are “double” field type with Length = 12 and Decimals = 6.

Thank you
Its work for me and will be save to the table only when the field longitute and latitude not hide. If the field is hide (visible=false) value longitude and latitude can’t save to the table
Do you have any solution?
Thanks

You may customize that code above that suits your needs. For example, get the value of Latitude and Longitude based on another certain client’s event, and then submit the values to database by using jQuery.

Good idea… Thank you…

is anybody success getting location on v2023?

It is the same. You should try and then post what difficulties you encountered.