Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

Collection of latitude and longitude from the client’s browser is a common theme in modern applications. While the user must allow location identification in their browser, when enabled, it can be helpful to track where users are. The example tracks the latitude and longitude of each save operation to a multi-value field.

The following script uses the browser’s native geolocation api to pull the users coordinates and writes them to a multi-value field named Geo Location.

var viewHash = 'locationAware-'+$$inject.properties.document.fileId;
if(!sessionStorage.getItem(viewHash)) {
    sessionStorage.setItem(viewHash, true)
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(gatherPosition);  
      return "Position set";
    }
    return "Position could not be set.";
}

function gatherPosition(position){
    let geoData = "Latitude: " + position.coords.latitude + " Longitude: " + position.coords.longitude;
    let geoArray = $$inject.fields['Geo Location'];
    geoArray.push(geoData);
    $$inject.fields['Geo Location'] = geoArray;
}
  • No labels