To collect GPS data automatically with a form submission, see Automatic GPS Capture. For troubleshooting, see GPS Limitations.
GPS data in CommCare is captured in decimal degrees. It has 4 components, separated by a space character:
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:
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.
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):
Longitude: =MID(H2,SEARCH(" ",H2,1)+1,SEARCH(" ",H2,SEARCH(" ",H2,1)+1)-SEARCH(" ",H2,1))
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.
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:
if(/data/location1 = '', '', if(/data/location2 = '', '', distance(/data/location1, /data/location2)))