예제 #1
0
 public Element getKMLElement(Document doc) {
   Element root = doc.createElement("kml");
   root.appendChild(doc.createElement("start").appendChild(doc.createTextNode("" + startTime)));
   Element trailPoints = doc.createElement("trail-points");
   StringBuilder ptsSB = new StringBuilder("");
   for (TTLocation loc : locations) {
     appendLocationString(ptsSB, loc);
   }
   trailPoints.appendChild(doc.createTextNode(ptsSB.toString()));
   root.appendChild(trailPoints);
   Element stops = doc.createElement("stops");
   StringBuilder stopsSB = new StringBuilder("");
   for (Stop stop : getStops()) {
     appendLocationString(stopsSB, stop.getStartLocation());
   }
   stops.appendChild(doc.createTextNode(stopsSB.toString()));
   root.appendChild(stops);
   Element waypointsEle = doc.createElement("waypoints");
   for (Waypoint wp : waypoints) {
     Element wpEle = doc.createElement("waypoint");
     wpEle.appendChild(doc.createElement("name").appendChild(doc.createTextNode(wp.getName())));
     StringBuilder wpLocSB = new StringBuilder("");
     appendLocationString(wpLocSB, wp.getLocation());
     wpEle.appendChild(
         doc.createElement("location").appendChild(doc.createTextNode(wpLocSB.toString())));
     ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
     wp.getImage().compress(Bitmap.CompressFormat.JPEG, 80, outputStream);
     Log.d("Map getKMLELement()", "jpg output:" + outputStream.toString());
     wpEle.appendChild(
         doc.createElement("image").appendChild(doc.createTextNode(outputStream.toString())));
     waypointsEle.appendChild(wpEle);
   }
   root.appendChild(waypointsEle);
   // TODO checkpoints
   root.appendChild(doc.createElement("map-title").appendChild(doc.createTextNode(name)));
   root.appendChild(
       doc.createElement("path-distance")
           .appendChild(doc.createTextNode(Float.toString(totalDistance))));
   root.appendChild(
       doc.createElement("linear-distance")
           .appendChild(doc.createTextNode(Float.toString(linearDistance))));
   root.appendChild(
       doc.createElement("average-speed")
           .appendChild(doc.createTextNode(Float.toString(averageSpeed))));
   root.appendChild(
       doc.createElement("maximum-speed")
           .appendChild(doc.createTextNode(Float.toString(maximumSpeed))));
   root.appendChild(
       doc.createElement("start-elevation")
           .appendChild(doc.createTextNode(Float.toString(startAltitude))));
   root.appendChild(
       doc.createElement("end-elevation")
           .appendChild(doc.createTextNode(Float.toString(endAltitude))));
   root.appendChild(
       doc.createElement("trip-time")
           .appendChild(doc.createTextNode(Integer.toString((endTime - startTime) / 1000))));
   root.appendChild(doc.createElement("notes").appendChild(doc.createTextNode(notes)));
   return root;
 }
예제 #2
0
  public static final Map instanceOf(TTSQLiteOpenHelper sqLiteOpenHelper, int mapId) {
    Map map = new Map();
    SQLiteDatabase database = sqLiteOpenHelper.getReadableDatabase();
    Cursor cursor =
        database.query(
            TABLE_MAPS, ALL_MAP_COLUMNS, COLUMN_ID + " = " + mapId, null, null, null, null);
    cursor.moveToFirst();
    map.id = mapId;
    map.name = cursor.getString(cursor.getColumnIndex(COLUMN_NAME));
    map.startTime = cursor.getInt(cursor.getColumnIndex(COLUMN_START_TIME));
    map.endTime = cursor.getInt(cursor.getColumnIndex(COLUMN_END_TIME));
    map.averageSpeed = cursor.getFloat(cursor.getColumnIndex(COLUMN_AVERAGE_SPEED));
    map.totalDistance = cursor.getFloat(cursor.getColumnIndex(COLUMN_TOTAL_DISTANCE));
    map.linearDistance = cursor.getFloat(cursor.getColumnIndex(COLUMN_LINEAR_DISTANCE));
    map.maximumSpeed = cursor.getFloat(cursor.getColumnIndex(COLUMN_MAXIMUM_SPEED));
    map.maximumAltitude = cursor.getFloat(cursor.getColumnIndex(COLUMN_MAX_ALTITUDE));
    map.minimumAltitude = cursor.getFloat(cursor.getColumnIndex(COLUMN_MIN_ALTITUDE));
    map.startAltitude = cursor.getFloat(cursor.getColumnIndex(COLUMN_START_ALTITUDE));
    map.endAltitude = cursor.getFloat(cursor.getColumnIndex(COLUMN_END_ALTITUDE));
    map.notes = cursor.getString(cursor.getColumnIndex(COLUMN_NOTES));
    cursor.close();

    map.locations = TTLocation.getAll(sqLiteOpenHelper, mapId);
    map.waypoints = Waypoint.getAll(sqLiteOpenHelper, mapId);
    map.stops = Stop.getAll(sqLiteOpenHelper, mapId);

    return map;
  }