Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
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;
}

When a document with the Live Field above is opened, the location data is gathered and appended to the Geo Location field, which is defined as multi-value. The new data is appended to the existing multi-value data set, preserving the overall history of the field.