سؤال

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.

هل كانت مفيدة؟

المحلول

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.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top