Customize GPX export.
This commit is contained in:
parent
699c533789
commit
5d3b9a2dcb
|
|
@ -33,6 +33,8 @@ public class MainActivity extends AppCompatActivity implements LocationListener,
|
||||||
private final String TAG = MainActivity.class.getName();
|
private final String TAG = MainActivity.class.getName();
|
||||||
private Button exportButton;
|
private Button exportButton;
|
||||||
private WriteToFile writeToFile;
|
private WriteToFile writeToFile;
|
||||||
|
private static boolean includeComments = false;
|
||||||
|
private static Double accuracyThreshold = 2.0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
@ -93,7 +95,10 @@ public class MainActivity extends AppCompatActivity implements LocationListener,
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
GPX gpx = GPX.builder().addTrack(track -> track.addSegment(segment -> {
|
GPX gpx = GPX.builder().addTrack(track -> track.addSegment(segment -> {
|
||||||
for(LocationEntity location : binder.allLocations()){
|
for(LocationEntity location : binder.allLocations()){
|
||||||
segment.addPoint(locationToWayPoint(location));
|
WayPoint wayPoint = locationToWayPoint(location);
|
||||||
|
if(wayPoint != null) {
|
||||||
|
segment.addPoint(wayPoint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})).build();
|
})).build();
|
||||||
Log.d(TAG, "Built GPX.");
|
Log.d(TAG, "Built GPX.");
|
||||||
|
|
@ -111,6 +116,17 @@ public class MainActivity extends AppCompatActivity implements LocationListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
private static WayPoint locationToWayPoint(LocationEntity location) {
|
private static WayPoint locationToWayPoint(LocationEntity location) {
|
||||||
|
if(accuracyThreshold != null)
|
||||||
|
{
|
||||||
|
if(location.accuracy == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(location.accuracy > accuracyThreshold) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WayPoint.Builder builder = WayPoint.builder()
|
WayPoint.Builder builder = WayPoint.builder()
|
||||||
.lat(location.latitude)
|
.lat(location.latitude)
|
||||||
.lon(location.longitude)
|
.lon(location.longitude)
|
||||||
|
|
@ -128,30 +144,32 @@ public class MainActivity extends AppCompatActivity implements LocationListener,
|
||||||
builder.ele(location.altitude);
|
builder.ele(location.altitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder commentBuilder = new StringBuilder();
|
if(includeComments) {
|
||||||
|
StringBuilder commentBuilder = new StringBuilder();
|
||||||
|
|
||||||
if(location.isMock){
|
if (location.isMock) {
|
||||||
commentBuilder.append("Location is mock.\n");
|
commentBuilder.append("Location is mock.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location.accuracy != null) {
|
||||||
|
commentBuilder.append(String.format("Accuracy is expected to be within %s meters.\n", location.accuracy));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location.altitudeAccuracy != null) {
|
||||||
|
commentBuilder.append(String.format("Altitude accuracy is expected to be within %s meters.\n", location.altitudeAccuracy));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location.bearingAccuracy != null) {
|
||||||
|
commentBuilder.append(String.format("Bearing accuracy is expected to be within %s degrees.\n", location.bearingAccuracy));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location.speedAccuracy != null) {
|
||||||
|
commentBuilder.append(String.format("Speed accuracy is expected to be within %s meters per second.\n", location.speedAccuracy));
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.cmt(commentBuilder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(location.accuracy != null){
|
|
||||||
commentBuilder.append(String.format("Accuracy is expected to be within %s meters.\n", location.accuracy));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(location.altitudeAccuracy != null){
|
|
||||||
commentBuilder.append(String.format("Altitude accuracy is expected to be within %s meters.\n", location.altitudeAccuracy));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(location.bearingAccuracy != null){
|
|
||||||
commentBuilder.append(String.format("Bearing accuracy is expected to be within %s degrees.\n", location.bearingAccuracy));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(location.speedAccuracy != null){
|
|
||||||
commentBuilder.append(String.format("Speed accuracy is expected to be within %s meters per second.\n", location.speedAccuracy));
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.cmt(commentBuilder.toString());
|
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue