Пример #1
0
  /**
   * filters out nonessential points. A point is nonessential if it affects the path taken by less
   * than 5 meters
   *
   * @return The checkpoints of the trail in this map
   */
  public TTLocation[] getCheckpoints() {
    // starting point always relevant//
    ArrayList<TTLocation> checkpointList = new ArrayList<TTLocation>();
    checkpointList.add(locations[0]);

    int relevantPointIndex = 0;
    for (int locationIndex = 2; locationIndex < locations.length; locationIndex++) {
      TTLocation ptInQuestion = locations[locationIndex - 1];
      TTLocation relevantPt = locations[relevantPointIndex];

      // distance from the last relevant to the point in question//
      float distanceTo =
          relevantPt.distanceTo(ptInQuestion.getLongitude(), ptInQuestion.getLatitude());

      // if the point is less than 5m away, it can't affect the trail by more than 5m//
      if (distanceTo < 5) {
        continue;
      }

      // difference between the bearing from the relevant point to the point in question
      // and the bearing from the relevant point to the point after the point in question
      float bearingDifference =
          Math.abs(
              relevantPt.bearingTo(ptInQuestion.getLongitude(), ptInQuestion.getLatitude())
                  - relevantPt.bearingTo(
                      locations[locationIndex].getLongitude(),
                      locations[locationIndex].getLatitude()));

      // distance away from the point in question that the new path will take//
      double distanceOff = Math.sin(bearingDifference) * distanceTo;

      if (distanceOff > 5) {
        checkpointList.add(ptInQuestion);
        relevantPointIndex = locationIndex - 1;
      }
    }

    // the last point is always relevant and, as a result of the loop conditions,
    // never added by the loop//
    checkpointList.add(locations[locations.length - 1]);

    TTLocation[] array = new TTLocation[checkpointList.size()];
    return checkpointList.toArray(array);
  }
Пример #2
0
 /**
  * Convenience method for adding appending a location's information to a StringBuilder for use in
  * a KML export
  *
  * @param stopsSB StringBuilder to which to append the location info
  * @param loc TTLocation from which to get info
  */
 private void appendLocationString(StringBuilder stopsSB, TTLocation loc) {
   stopsSB
       .append(loc.getLongitude())
       .append(",")
       .append(loc.getLatitude())
       .append(",")
       .append(loc.getAccuracy())
       .append(",")
       .append(loc.getAltitude())
       .append(",")
       .append(loc.getAccuracy())
       .append(",")
       .append(loc.getSpeed())
       .append(",")
       .append(loc.getTime())
       .append(",")
       .append(loc.getTime() / 1000)
       .append(",")
       .append(loc.getDistance())
       .append(";")
       .append("\n");
 }