我创建了sqlite数据库,它存储纬度,经度和其他一些信息,如描述。
现在我想提取此信息并将GPX文件写入SD卡以进行进一步分析。任何人都知道如何做到这一点?
任何有用的链接,来源等?
答案 0 :(得分: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;
}
答案 1 :(得分:0)
到目前为止,我发现编写和阅读GPX的最佳解决方案是: http://sourceforge.net/projects/gpxparser/
答案 2 :(得分:-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());
}