从GeoPoints创建GPX文件

JiT*_*HiN 8 android google-maps gpx android-maps

有没有办法导出GeoPoints到GPX文件?

@Override
public void onLocationChanged(android.location.Location location) {
        lat = location.getLatitude();
        lon = location.getLongitude();
        currGeo = new GeoPoint((int)(lat*1e6),(int)(lon*1e6));

        //Store GeoPoint to GPX file
    }
Run Code Online (Sandbox Code Playgroud)

我已经阅读了如何解析和绘制gpx文件有一个android MapView,但我正在寻找一个更简单的解决方案.

Tra*_*vis 3

如果您只想从地理点列表生成 GPX 文件,最简单的方法是将字符串爆炸到文件中。由于不知道 GPX 的确切格式,我正在编写很多细节,但您应该知道您正在生成的格式。例如,在伪代码中:

// open file handle
OutputStream fout = getFileOutputStream("gpxFile.gpx");
fout.write("<gpx>");
for (GeoPoint gp : listOfGeoPoints) {
    fout.write("<gpxPoint>" + getGeoPointAsStringForFile(gp) + "</gpxPoint>"); 
}
fout.write("</gpx>");
// close file, cleanup, etc
Run Code Online (Sandbox Code Playgroud)

这需要您实现 getFIleOutputStream() 方法和 getGeoPointAsStringForFile() 方法,但您知道您的目标格式是什么,这将让您只需创建文件而无需经历很多麻烦。

  • 应该指出的是,这是非常脆弱的,因此在上线之前请以正确的方式进行操作,但这是一个简短版本的快速修复。