Create GPX file from GeoPoints
Asked Answered
A

1

8

Is there any way to export GeoPoints into a GPX file?

@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
    }

I've read How to parse and plot gpx file has an android MapView, but I'm looking for a more simpler solution.

Aerobatics answered 23/8, 2012 at 11:20 Comment(0)
S
3

If you ONLY want to generate a GPX file from a list of geopoints, the simplest way would be to just blast strings into a file. Not knowing the exact format of GPX, I'm making a lot of the details up, but you should know the format you're generating. For Example, in pseudocode:

// 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

This would require you to implement the getFIleOutputStream() method and the getGeoPointAsStringForFile() method, but you know what format you're aiming for, and this'll let you just create the file without having to go through a lot of hoops.

  • It should be noted that this is incredibly fragile, so do it the right way before you go live, but this is a short version quick fix.
Sacristan answered 7/11, 2012 at 17:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.