2

我创建了存储纬度、经度和其他一些信息(如描述)的 sqlite 数据库。

现在我想提取这些信息并将 GPX 文件写入我的 SD 卡以进行进一步分析。任何人都知道如何做到这一点?

任何有用的链接、来源等?

4

3 回答 3

1

谢谢朋友。以上两个链接帮助我解决了我的问题,这是将数据库值写入 .kml 文件的代码

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());
                            }

这是从数据库中读取值的示例

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;
}
于 2012-04-26T10:01:38.313 回答
0

到目前为止,我为编写和阅读 GPX 找到的最佳解决方案是:http: //sourceforge.net/projects/gpxparser/

于 2013-09-25T21:29:54.767 回答
-2

这里是:

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());
}
于 2012-04-20T07:37:28.953 回答