Exemplo n.º 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;
 }
Exemplo n.º 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");
 }