使用 SAX 解析器或 XmlPullParser 解析 GPX 文件
我的应用程序创建了许多 gpx 文件,需要在应用程序的稍后阶段进行解析。 一般来说,我在解析它们时遇到困难。我在这个网站和其他网站上看到了很多解析器的示例,但它们都使用 Tracks
和 TrakcPoints
等对象,但找不到这些类包含的内容。我真的希望能够解析该文件并将其排序到 Location
的 ArrayList
中。我需要从文件中获取经度和纬度以及时间和海拔。
有人可以帮我解决这个问题吗? 我不介意使用 SAX 解析器
或 Xml pull 解析器
或其他方法。
I have a number of gpx files that my app creates and will need to parse at a later stage in the app.
I'm having trouble parsing them in general. I've seen alot of examples of parsers on this site and others but they all use objects like Tracks
and TrakcPoints
but what these classes contain can't be found. I would really like just to be able to parse the file and sort it into an ArrayList
of Location
. I will need to get the long and lat from the file as well as the time and elevation.
Can some one help me with this problem?
I don't mind if use SAX parser
or an Xml pull parser
or another method of doing it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
想通了,可能不是最优雅的方式,但它有效
希望这可以帮助一些人
Figured it out, might not be the most elegant way of doing it but it works
Hope this helps some people
使用 SAX:
GpxImportActivity.java
GpxFileContentHandler.java
with SAX:
GpxImportActivity.java
GpxFileContentHandler.java
即用型、开源且功能齐全的 java GpxParser(以及更多)在这里
https://sourceforge.net/projects/geokarambola/
详细信息请参见此处
https://plus.google.com/u/0/communities/110606810455751902142
使用上述库解析 GPX 文件是一件简单的事情:
获取其点、路线或轨迹是微不足道的太:
然后你可以迭代路线的点并直接获取它们的纬度/经度/海拔高度
Ready to use, open source, and fully functional java GpxParser (and much more) here
https://sourceforge.net/projects/geokarambola/
Details here
https://plus.google.com/u/0/communities/110606810455751902142
With the above library parsing a GPX file is a one liner:
Getting its points, routes or tracks trivial too:
Then you can iterate the route's points and get their lat/lon/ele directly