gpt4 book ai didi

android - 将经纬度从数据库保存到 GPX 文件.Android

转载 作者:行者123 更新时间:2023-11-29 14:16:09 32 4
gpt4 key购买 nike

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

现在我想提取此信息并将其写入 GPX 文件到我的 SD 卡中以供进一步分析。有人知道如何执行此操作吗?

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

最佳答案

谢谢 friend 。以上两个链接帮助我解决了我的问题,这是将数据库值写入 .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;
}

关于android - 将经纬度从数据库保存到 GPX 文件.Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10241971/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com