2012-04-20 3 views
1

위도, 경도 및 설명과 같은 다른 정보를 저장하는 sqlite 데이터베이스를 만들었습니다.데이터베이스에서 GPX 파일로 lat long을 저장합니다 .Android

이제이 정보를 추출하여 추가 분석 목적으로 내 SD 카드에 GPX 파일로 작성하고 싶습니다. 누구든지이 작업을 수행하는 방법에 대해 알고 있습니까?

유용한 링크, 소스 등은 무엇입니까?

답변

1

감사합니다 친구. 두 개의 링크가 내 문제를 해결하는 데 도움이보다도, 여기에 파일을

try { 
           File root = Environment 
             .getExternalStorageDirectory(); 
           if (root.canWrite()) { 
            File gpxfile = new File(root, "" 
              + value + ".kml"); 
            FileWriter gpxwriter = new FileWriter(
              gpxfile); 
            BufferedWriter out = new BufferedWriter(
              gpxwriter); 
            out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" 
              + "\n" 
              + "<kml xmlns=\"http://www.opengis.net/kml/2.2\">" 
              + "\n" + "<Folder>" + "\n"); 
            for (int i = 0; i < latarray.length; i++) { 
             out.write("<Placemark>" + "\n" 
               + "<name> Point " 
               + i 
               + "</name>" 
               + "\n" 
               + "<description>" 
               + "" 
               + discription[i] 
               + "</description>" 
               + "\n" 
               + "<Point>" 
               + "\n" 
               + "<coordinates>" 
               + "" 
               + (lonarray[i]/(1E6)) 
               + "," 
               + "" 
               + (latarray[i]/(1E6)) 
               + "," 
               + "" 
               + accuarray[i] 
               + "</coordinates>" 
               + "\n" 
               + " </Point>" 
               + "\n" 
               + "</Placemark>" + "\n"); 
            } 
            out.write("</Folder>" + "\n" + "</kml>"); 
            out.close(); 
            mydb.close(); 
           } 
          } catch (IOException e) { 
           Log.e("Cant write", "Could not write file " 
             + e.getMessage()); 
          } 

을 .KML하는 데이터베이스 값을 작성하기위한 코드는 여기에 데이터베이스

public int[] lattodraw() { 
    // TODO Auto-generated method stub 

    String[] columns = new String[] { KEY_ROWID, KEY_Latitude, 
      KEY_Longitude, KEY_Accuracy, KEY_ROWID, KEY_Latitude, 
      KEY_Longitude, KEY_Accuracy, KEY_Discription, KEY_North, 
      KEY_East, KEY_South, KEY_West }; 
    Cursor locationCursor = ourDatabase.query(DATABASE_TABLE, columns, 
      null, null, null, null, null); 

    locationCursor.moveToFirst(); 
    int count = locationCursor.getCount(); 
    int latarray[] = new int[count]; 
    int i = 0; 
    do { 

     int latitude = (int) (locationCursor.getDouble(locationCursor 
       .getColumnIndex(KEY_Latitude)) * 1E6); 

     latarray[i] = latitude; 
     i++; 
    } while (locationCursor.moveToNext()); 
    locationCursor.close(); 
    return latarray; 
} 
-1

는 여기있다 :

try { 
    File root = Environment.getExternalStorageDirectory(); 
    if (root.canWrite()){ 
     File gpxfile = new File(root, "gpxfile.gpx"); 
     FileWriter gpxwriter = new FileWriter(gpxfile); 
     BufferedWriter out = new BufferedWriter(gpxwriter); 
     out.write("Hello world"); 
     out.close(); 
    } 
} catch (IOException e) { 
    Log.e(TAG, "Could not write file " + e.getMessage()); 
} 
관련 문제