Update of longitude and latitude in sales invoice

Does anyone know how to implement the update of longitude and latitude for the current location after clicking the ‘Submit’ button for a sales invoice in ERPNext

Add location field.
Write custom script on the front end

frappe.ui.form.on(‘Sales Invoice’, {
submit: function(frm){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
doc.latitude = position.coords.latitude;
doc.longitude = position.coords.longitude;
// set the coordinate field(s) here
}, function(error) {
frappe.throw(("Geolocation error: ") + error.message);
});
} else {
frappe.throw(
(“Geolocation is not supported by your browser.”));
}
}
});