Skip to main content


         This documentation site is for previous versions. Visit our new documentation site for current releases.      
 

This content has been archived and is no longer being updated.

Links may not function; however, this content may be relevant to outdated versions of the product.

Tracking user location with offline-enabled mobile apps

Updated on September 4, 2019

This tutorial describes how to configure your offline-enabled app to record and synchronize device location data. The Pega Mobile Client™ API set contains a Location Recorder API, which allows offline-enabled mobile apps to record and store geolocation information about a mobile device. Collected while the device is disconnected from the network, this information can later, after the device regains connectivity, be transferred to Pega Platform™ to provide aggregated information about where a user has been. For example, you can use this feature to record work time and the route of a delivery truck traveling in areas with poor network coverage.

As a Pega Platform application administrator, you can customize your application to use this recorded location information. You configure and initiate the location recording feature at the Pega Platform application level. You can configure the recording frequency, as well as data synchronization frequency. Synchronized data is then passed through a customizable activity and stored in the database.

You must ensure that your application has been configured to support offline mode. For more information, see Working with offline apps.

Prerequisites

Before you start this tutorial, you must meet the following requirements:

Setting up the Location Recorder API

To create, configure, and initiate a recorder from within a Pega Platform application, you must use the Location Recorder API.

  1. Right-click and download the following file that contains a JavaScript application that uses the API:

    LocationRecorderExample.zip (0.1 MB)

  2. Review the contents of the JavaScript application to learn how to configure and initiate the API.

  3. Create a custom JavaScript that makes use of the API and associate it with a control in your Pega Platform application, for example, a button.

Configuring the activity rule

After you create and modify your Pega Platform application, clone the pyProcessGeolocationData activity rule to enable data capture.

  1. Search for the pyProcessGeolocationData activity rule by using the search text field in Designer Studio.
  2. Click Save As >Specialize by class or ruleset to create a clone of the rule with the same name.
  3. Specify the context by selecting the @baseclass class in the Apply to field in your application ruleset, and click Create and open.
  4. When the activity rule opens, in the Steps tab, click the right angle bracket (>) to display the Java code behind the rule, similar to the following code:
    String recorderID = tools.getParamValue("recorderID");
    oLog.infoForced("recorderID: " + recorderID);
    ParameterPage parametersPage = tools.getParameterPage();
    Object locationsJSON = parametersPage.getParameterValue("locationsJson");
    org.json.simple.JSONArray json = (org.json.simple.JSONArray)locationsJSON;
    Iterator locationsBatch = json.iterator();

    while (locationsBatch.hasNext()) {
    org.json.simple.JSONObject batch = (org.json.simple.JSONObject)locationsBatch.next();
    oLog.infoForced("attributes: " + batch.get("attributes"));
    oLog.infoForced("columns: " + batch.get("columns"));

    org.json.simple.JSONArray locationsArray = (org.json.simple.JSONArray)batch.get("locations");
    Iterator locations = locationsArray.iterator();
    while (locations.hasNext()) {
    oLog.infoForced(" location: " + locations.next());
    }
    }
  5. The existing code writes the collected geolocation data to system logs. You can modify the code according to your needs.
  6. Click Save to apply your changes to the pyProcessGeolocationData activity rule.

Have a question? Get answers now.

Visit the Support Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega.com is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us