Calculate elevation - just a test right now (see #28)

master
y20k 2018-01-29 16:49:13 +01:00
parent ca0b9017d9
commit ed0d53e336
2 changed files with 40 additions and 0 deletions

View File

@ -559,6 +559,10 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
// todo remove
StorageHelper storageHelper = new StorageHelper(mActivity);
storageHelper.calculateTrackElevation(mTrack);
// display track on map
displayTrack();
}

View File

@ -17,6 +17,7 @@
package org.y20k.trackbook.helpers;
import android.content.Context;
import android.location.Location;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.support.v4.os.EnvironmentCompat;
@ -358,4 +359,39 @@ public class StorageHelper implements TrackbookKeys {
return null;
}
/* Calculates positive and negative elevation of track */ // todo make private
public Track calculateTrackElevation(@Nullable Track track) {
double positiveElevation = 0;
double negativeElevation = 0;
double LIKELY_MEASUREMENT_ERROR = 25; // move to TrackbookKeys
if (track != null && track.getWayPoints().size() > 0 && track.getWayPointLocation(0).getAltitude() != 0) {
Location previousLocation;
Location nextLocation;
// iterate over track
for (int i = 0; i < track.getWayPoints().size() - 1; i++ ) {
// calculate elevation difference
previousLocation = track.getWayPointLocation(i);
nextLocation = track.getWayPointLocation(i + 1);
double difference = nextLocation.getAltitude() - previousLocation.getAltitude();
LogHelper.i(LOG_TAG, "next:" + nextLocation.getAltitude() + " | prev:" + previousLocation.getAltitude() + " | diff:" + difference); // todo remove
// add difference to elevation
if (difference > 0 && difference < LIKELY_MEASUREMENT_ERROR) {
positiveElevation = positiveElevation + difference;
} else if (difference < 0 && difference > -LIKELY_MEASUREMENT_ERROR) {
negativeElevation = negativeElevation + difference;
}
}
String toastString = "Calculated elevation: +" + positiveElevation + " / " + negativeElevation + " meters"; // todo remove
Toast.makeText(mContext, toastString, Toast.LENGTH_LONG).show(); // todo remove
LogHelper.i(LOG_TAG, toastString); // todo remove
}
return track;
}
}