Location Recorder example


The following examples show how you can use various methods of the Location Recorder API.

Creating a new instance of the Recorder object.

launchbox.PRPC.LocationRecorder.recorder("case_id")  
.then(function(recorder) {  
  console.log("Obtained recorder instance with 'id': " + recorder.identifier);  
});

Listing existing instances of the Recorder object.

launchbox.PRPC.LocationRecorder.availableRecorders()  
.then(function(dictionary) {  
  console("Available recorder with ids: " + Object.keys(dictionary));  
  if (dictionary.foo !== undefined) {  
    var recorder = dictionary.foo;  

    // do something  

  }  
});

Configuring an existing instance of the Recorder object.

// If you want to use a custom configuration, create a 'Configuration' object...
var configuration = new launchbox.PRPC.LocationRecorder.Configuration();  
  
// ...modify the properties according to your needs...

// Defaults to true.
configuration.enableHighAccurracy = false;
  
// Defaults to 5.0 meters.
configuration.distanceFilter = 20.5;
  
// Defaults to 10 seconds.
configuration.minimalLocationRetrievalInterval = 60;
  
// Defaults to an empty object.
configuration.customAttributes = {'foo': 42, 'bar': false};
  
// Defaults to Infinity.
configuration.workingPeriod = 60 * 60 * 8;
  
// ...and pass configuration object to the <code>Recorder</code> object.
recorder.configuration = configuration;

Initiating the recording.

// This operation can throw:
// launchbox.PRPC.LocationRecorder.LocationServicesPermissionError - when an application has no permissions to use Location Services,
// launchbox.PRPC.LocationRecorder.IllegalOperationError - when the recorder is already started or stopped,
// launchbox.PRPC.LocationRecorder.LocationClientStoreClosedError - when the ClientStore is closed.

recorder.start()  
.then(function() {  
  console.log("Recorder has started succesfully");  
}).catch(function(error) {  

  // Error handling  

});

Pausing and resuming the recording.

// This operation can throw:
// launchbox.PRPC.LocationRecorder.IllegalOperationError - when the recorder is in any other state than 'RECORDING'.

recorder.pause().then(function() {
  console.log("Recorder has paused recording.");
}).catch(function(error) {

  // Error handling

});

// This operation can throw:
// launchbox.PRPC.LocationRecorder.IllegalOperationError - when the recorder is in any other state than 'PAUSED'.

recorder.resume().then(function() {
  console.log("Recorder has resumed recording.");
}).catch(function(error) {

  // Error handling

});

Stopping the recording.

// This operation can throw:
// launchbox.PRPC.LocationRecorder.IllegalOperationError - when the recorder is already in 'STOPPED' state.
recorder.stop().then(function() {
  console.log("Recorder stopped successfully.");
}).catch(function(error) {

  // Error handling

});

Invalidating an instance of the Recorder object.

recorder.invalidate().then(function() {  
  console.log("Recorder invalidated successfully.");  
});

Tracking the status of the Recorder object.

recorder.status;
// Status
launchbox.PRPC.LocationRecorder.Status = new Enum({
  "STOPPED",
  "RECORDING",
  "PAUSED",
  "INVALIDATED"  
});

var onStatusChangedHandler = function(recorder, error) {
  console.log("Recorder status has changed to: " + recorder.status);
if (error !== undefined) {
     console.log("Recorder failed with error: " + error.message);
}
};

// see ObservableEvent.js

recorder.onStatusChanged.bind(onStatusChangedHandler);
recorder.onStatusChanged.unbind(onStatusChangedHandler);

Related topics

Public API reference
Geolocation
Legal notice | Copyright © 2017 and Confidential to Pegasystems Inc. All rights reserved
PDN | Pega Mobile Client | Feedback
Advanced...