Parsing local gpx file in Android

前端 未结 4 1495
闹比i
闹比i 2021-01-02 11:10

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

4条回答
  •  清歌不尽
    2021-01-02 11:37

    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.

提交回复
热议问题