Ejemplo n.º 1
0
  /**
   * Going to assume date is always in the form:<br>
   * 2006-05-25T08:55:01Z<br>
   * 2006-05-25T08:56:35Z<br>
   * <br>
   * i.e.: yyyy-mm-ddThh-mm-ssZ <br>
   * code from Tommi Laukkanen http://www.substanceofcode.com
   *
   * @param dateString
   * @return
   */
  private static Date parseDate(String dateString) {
    try {
      final int year = Integer.parseInt(dateString.substring(0, 4));
      final int month = Integer.parseInt(dateString.substring(5, 7));
      final int day = Integer.parseInt(dateString.substring(8, 10));

      final int hour = Integer.parseInt(dateString.substring(11, 13));
      final int minute = Integer.parseInt(dateString.substring(14, 16));
      final int second = Integer.parseInt(dateString.substring(17, 19));

      Calendar calendar = Calendar.getInstance();
      calendar.set(Calendar.YEAR, year);
      calendar.set(
          Calendar.MONTH,
          month - 1); // Beware MONTH was counted for 0 to 11, so we have to subtract 1
      calendar.set(Calendar.DAY_OF_MONTH, day);
      calendar.set(Calendar.HOUR_OF_DAY, hour);
      calendar.set(Calendar.MINUTE, minute);
      calendar.set(Calendar.SECOND, second);

      return calendar.getTime();
    } catch (Exception e) {
      Log.err(log, "RouteOverlay", "Exception caught trying to parse date : ", e);
    }
    return null;
  }
Ejemplo n.º 2
0
  public static void SaveRoute(String Path, Track track) {
    FileWriter writer = null;
    File gpxfile = FileFactory.createFile(Path);
    try {
      writer = gpxfile.getFileWriter();
      try {
        writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        writer.append(
            "<gpx version=\"1.0\" creator=\"cachebox track recorder\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.topografix.com/GPX/1/0\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\n");

        Date now = new Date();
        SimpleDateFormat datFormat = new SimpleDateFormat("yyyy-MM-dd");
        String sDate = datFormat.format(now);
        datFormat = new SimpleDateFormat("HH:mm:ss");
        sDate += "T" + datFormat.format(now) + "Z";
        writer.append("<time>" + sDate + "</time>\n");

        writer.append("<bounds minlat=\"-90\" minlon=\"-180\" maxlat=\"90\" maxlon=\"180\"/>\n");

        writer.append("<trk>\n");
        writer.append("<name>" + track.Name + "</name>\n");
        writer.append("<extensions>\n<gpxx:TrackExtension>\n");
        writer.append("<gpxx:ColorRGB>" + track.mColor.toString() + "</gpxx:ColorRGB>\n");
        writer.append("</gpxx:TrackExtension>\n</extensions>\n");
        writer.append("<trkseg>\n");
        writer.flush();
      } catch (IOException e) {
        Log.err(log, "SaveTrack", e);
      }
    } catch (IOException e1) {
      Log.err(log, "SaveTrack", e1);
    }

    try {
      for (int i = 0; i < track.Points.size(); i++) {
        writer.append(
            "<trkpt lat=\""
                + String.valueOf(track.Points.get(i).Y)
                + "\" lon=\""
                + String.valueOf(track.Points.get(i).X)
                + "\">\n");

        writer.append(
            "   <ele>"
                + String.valueOf(String.valueOf(track.Points.get(i).Elevation))
                + "</ele>\n");
        SimpleDateFormat datFormat = new SimpleDateFormat("yyyy-MM-dd");
        String sDate = datFormat.format(track.Points.get(i).TimeStamp);
        datFormat = new SimpleDateFormat("HH:mm:ss");
        sDate += "T" + datFormat.format(track.Points.get(i).TimeStamp) + "Z";
        writer.append("   <time>" + sDate + "</time>\n");
        writer.append("</trkpt>\n");
      }
      writer.append("</trkseg>\n");
      writer.append("</trk>\n");
      writer.append("</gpx>\n");
      writer.flush();
      writer.close();
    } catch (IOException e) {
      Log.err(log, "SaveTrack", e);
    }
    writer = null;
  }