Articles on: Process execution
This article is also available in:

Georeferencing and Geolocation

Georeferencing and Geolocation



Depending on the type of process we are automating it may be important to obtain the location of the user who is completing the task.

Add a field to the form, for example "GPS", which should be a text type.

Then click on "Visibility settings and scripts" and go to the third tab "Script" in the popup that opens.

Select the task you want (e.g. to create a document so that the location is loaded when a request is being entered)

And paste the following script:

function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
console.log("Geolocation is not supported by this browser.");
}
}
function showPosition(position) {
Flokzu.setFieldValue( [[GPS]] , "Latitud: " + position.coords.latitude +
" Longitud: " + position.coords.longitude);
}
Flokzu.onInit(getLocation);

Here's what happens:


With Flokzu.onInit (i.e. when the form is loaded), we call the function getLocation.
The function getLocation, asks the browser for the current location.
Once the location is obtained, the function getLocation will call the function showPosition that by means of Flokzu.setFieldValue will load in the GPS field, the current position in a format "Latitude: -34.898676 Longitude: -56.1533002".

The first time, the user will be asked for permission to access the location.


Updated on: 05/03/2020

Was this article helpful?

Share your feedback

Cancel

Thank you!