2010-11-29 5 views
0

나는 kml 파일을 파싱하여 쓰고, sd card에 저장하고있는 프로젝트에서 일하고 있습니다.하지만 문제가 있습니다. Google지도에서 좌표가 모두 필요한 경로를 추적하기 때문에 내 Activity안드로이드에서 KMF 구문 분석

<?xml version="1.0"?> 
<kml xmlns="http://www.opengis.net/kml/2.2"> 
    <Placemark> 
     <name>Untitled Path</name> 
     <Style id="RedLine"> 
      <LineStyle> 
       <color>7f0000ff</color> 
       <width>4</width> 
      </LineStyle> 
     </Style> 
     <styleUrl>#RedLine</styleUrl> 
     <LineString> 
      <tessellate>1</tessellate> 
      <altitudeMode>absolute</altitudeMode> 
      <coordinates> 
        -7.178449630737305,41.48063600063324,274.0 
      </coordinates> 
     </LineString> 
    </Placemark> 
    <Placemark> 
     <name>Untitled Path</name> 
     <Style id="RedLine"> 
      <LineStyle> 
        <color>7f0000ff</color> 
        <width>4</width> 
      </LineStyle> 
     </Style> 
     <styleUrl>#RedLine</styleUrl> 
     <LineString> 
      <tessellate>1</tessellate> 
      <altitudeMode>absolute</altitudeMode> 
      <coordinates> 
       -7.178449630737305,41.48063600063324,274.0 
      </coordinates> 
     </LineString> 
    </Placemark> 
</kml> 

을 그리고 내 주요 클래스 : 그냥이 kml 출력 좋아해요 내가 잘못 무엇

private void WriteToFile(Location loc) { 
    if (!logToGpx && !logToKml) { 
     return; 
    } 
    try { 
     boolean brandNewFile = false; 
     // if (root.canWrite()){ 
     // File gpxFolder = new File("/sdcard/GPSLogger"); 
     File gpxFolder = new File(Environment.getExternalStorageDirectory(), "GPSLogger"); 
      Log.i("MAIN", String.valueOf(gpxFolder.canWrite())); 
      if (!gpxFolder.exists()) { 
       gpxFolder.mkdirs(); 
       brandNewFile = true; 
      } 
      if (logToGpx) { 
       WriteToGpxFile(loc, gpxFolder, brandNewFile); 
      } 
      if (logToKml) { 
       WriteToKmlFile(loc, gpxFolder, brandNewFile); 
      } 
    } catch (Exception e) { 
     Log.e("Main", "Nao foi possivel criar o ficheiro " + e.getMessage()); 
     SetStatus("Nao e possivel escrever no ficheiro. " + e.getMessage()); 
    } 
} 

private void WriteToKmlFile(Location loc, File gpxFolder, boolean brandNewFile) { 
    try { 
     File kmlFile = new File(gpxFolder.getPath(), currentFileName + ".kml"); 
     if (!kmlFile.exists()) { 
       kmlFile.createNewFile(); 
       brandNewFile = true; 
     } 
     Date now = new Date(); 
     //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); 
     //String dateTimeString = sdf.format(now); 
     if (brandNewFile) { 
       FileOutputStream initialWriter = new FileOutputStream(kmlFile, true); 
       BufferedOutputStream initialOutput = new BufferedOutputStream(initialWriter); 
       String initialXml = "<?xml version=\"1.0\"?>"+ "<kml xmlns=\"http://www.opengis.net/kml/2.2\">" + "</kml>"; 
       initialOutput.write(initialXml.getBytes()); 
       // initialOutput.write("\n".getBytes()); 
       initialOutput.flush(); 
       initialOutput.close(); 
     } 

     long startPosition = kmlFile.length() - 6; 

     String placemark = "<Placemark><name>" + now.toLocaleString() 
      + "</name><description>" + now.toLocaleString() 
      + "</description>" + "<Point><coordinates>" 
      + String.valueOf(loc.getLongitude()) + "," 
      + String.valueOf(loc.getLatitude()) + "," 
      + String.valueOf(loc.getAltitude()) 
      + "</coordinates></Point></Placemark></kml>"; 

     RandomAccessFile raf = new RandomAccessFile(kmlFile, "rw"); 
     raf.seek(startPosition); 
     raf.write(placemark.getBytes()); 
     raf.close(); 

     } catch (IOException e) { 
      Log.e("Main", "Error in writting " + e.getMessage()); 
      SetStatus("Error in writting. " + e.getMessage()); 
     } 
} 

? 당신은 내가 좌표가 모두 함께

좌표가 <coordinates> 태그에 모두 함께있는 것을 필요

으로 무엇을 의미하는지

답변

0

경로를 그리는 방법을, 같은 장소에있는 모든 점을 넣고 유도 선 는인가요 무엇 너는하고 싶어? 질문은 명확하지 않습니다.

<PlaceMark> 
... 
<LineString> 
    ... 
    <coordinates> 
    -7.178449630737305,41.48063600063324,274.0 
    ... append other points here .... 
    </coordinates> 
</LineString> 
</PlaceMark> 
관련 문제