GPS data in CommCare is captured in decimal degrees. It has 4 components, separated by a space character:
Latitude: in decimal degrees
Longitude: in decimal degrees
Elevation: in metres, and
Precision / Accuracy: in metres
For example, a data point collected in CommCare and viewed through form data may look something like 25.615311244889146 85.08323017699811 28.44 20.0, where:
25.615311244889146 specifies the latitude in decimal degrees
85.08323017699811 specifies the longitude in decimal degrees
28.44 specifies the elevation in metres, and
20.0 specifies the precision in metres.
Mapping the Data
GPS data in CommCare is captured in decimal degrees. It is easy to make a map using Google Earth.
Google Earth requires a kml file. You can generate a kml file using an Excel file and a free converter like this one.
Export data from CommCareHQ into Excel
If all of the coordinates are in one cell, select the GPS coordinates field and use the Excel "text to columns" feature to separate the GPS field into its 4 component fields (latitude, longitude, elevation, precision). You can delete the elevation and precision columns for a basic map.
Use the following formulas to extract latitude and longitude (in this example, H2 is the cell that contains the full GPS coordinates. Replace H2 with whatever cell contains your GPS coordinates):
The location returned by a GPS question is a string composed of the latitude, longitude, altitude and accuracy, each separated by a space. In your export configuration, if you choose "Expand Checkbox Questions" then the GPS data will automatically be split into four columns.
If all of the coordinates are in one cell, the following expression will extract the latitude from the location: if(/data/location = '', '', selected-at(/data/location, 0))
Similarly, for longitude: if(/data/location = '', '', selected-at(/data/location, 1))
When using the Auto-Location capture feature, that GPS location is available through /data/meta/location and can be accessed by enabling "Show Advanced Questions" in a form export.
Calculating Distances Between GPS Coordinates
CommCare now supports distance calculation via the distance XPath function on both J2ME and Android phones. For example, the following expression returns the distance between two locations in meters:
Since the distance function returns -1 if either argument is an empty string, a more robust way to display the distance is shown below: