List<Wgs84Position> positions = route.getPositions();
Wgs84Position previous = null;
double distance = 0.0;
for (int i = startIndex; i < endIndex; i++) {
Wgs84Position position = positions.get(i);
TrackpointT trackpointT = objectFactory.createTrackpointT();
trackpointT.setAltitudeMeters(position.getElevation());
trackpointT.setHeartRateBpm(getHeartBeatRateT(position));
trackpointT.setPosition(createPosition(position));
trackpointT.setTime(formatTime(position.getTime()));
if (previous != null) {
distance += previous.calculateDistance(position);
}
previous = position;
trackpointT.setDistanceMeters(distance);
trackpoints.add(trackpointT);
}
return trackT;
}