Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing local gpx file in Android

I followed this example to parse a local GPX file in Android: http://android-coding.blogspot.pt/2013/01/get-latitude-and-longitude-from-gpx-file.html

All works fine to access "lat" and "long" but I need also to get the "ele" value but all my tentatives were unsuccessful. Anyone can give me some hits to do that?

Thanks in advance! Best regards, NR.

like image 935
user2649377 Avatar asked Sep 06 '13 14:09

user2649377


1 Answers

I will add my library for GPX parsing to these answers: https://github.com/ticofab/android-gpx-parser. It provides two ways to parse you GPX file: once you obtain / create a GPXParser object (mParser in the examples below), you can then either parse directly your GPX file

Gpx parsedGpx = null;
try {
    InputStream in = getAssets().open("test.gpx");
    parsedGpx = mParser.parse(in);
} catch (IOException | XmlPullParserException e) {
    e.printStackTrace();
}
if (parsedGpx == null) {
    // error parsing track
} else {
    // do something with the parsed track
}

or you can parse a remote file:

mParser.parse("http://myserver.com/track.gpx", new GpxFetchedAndParsed() {
    @Override
    public void onGpxFetchedAndParsed(Gpx gpx) {
        if (gpx == null) {
            // error parsing track
        } else {
            // do something with the parsed track
        }
    }
});

Contributions are welcome.

like image 88
ticofab Avatar answered Sep 17 '22 15:09

ticofab