- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我按照教程学习解析 gpx 文件(位于我的原始文件夹中)中的数据,但出于某种原因,没有数据被解析到 NodeList 中。这是我的 XMLParser 类
package bry.Bicker.OjaiHiking;
import java.io.IOException;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import android.util.Log;
public class XMLParser {
public Document getDomElement(String xml) {
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
doc = db.parse(is);
} catch (ParserConfigurationException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (SAXException e) {
Log.e("Error: ", e.getMessage());
return null;
} catch (IOException e) {
Log.e("Error: ", e.getMessage());
return null;
}
// return DOM
return doc;
}
public String getValue(Element e, String str) {
NodeList n = e.getElementsByTagName(str);
return this.getElementValue(n.item(0));
}
public final String getElementValue(Node elem) {
Node child;
if (elem != null) {
if (elem.hasChildNodes()) {
for (child = elem.getFirstChild(); child != null; child = child
.getNextSibling()) {
if (child.getNodeType() == Node.TEXT_NODE) {
return child.getNodeValue();
}
}
}
}
return "";
}
}
下面是我尝试使用类来解析文件的方式:
public void displayPoints(MapView map, Context context) {
final String KEY_TRKPT = "trkpt";
final String KEY_LAT = "lat";
final String KEY_LON = "lon";
XMLParser parser = new XMLParser();
Document doc = parser.getDomElement(getString(R.raw.test));
NodeList n1 = doc.getElementsByTagName(KEY_TRKPT);
if (n1.getLength() > 0) {
int[] lat = new int[n1.getLength()];
int[] lon = new int[n1.getLength()];
for (int i = 0; i < n1.getLength(); i++) {
org.w3c.dom.Element e = (org.w3c.dom.Element) n1.item(i);
lat[i] = Integer.parseInt(parser.getValue(e, KEY_LAT));
lon[i] = Integer.parseInt(parser.getValue(e, KEY_LON));
}
} else {
Log.i("Debug", "XML Parsing error. No data in nodelist.");
}
}
并且 GPX 文件是从应用程序“MyTracks”中导出的。
我没有收到任何错误,但我的消息显示“XML 解析错误。节点列表中没有数据。”被展示。
最佳答案
有一些有用的库——包括我的。查看 this other question on StackOverflow 的答案.基本上我的库提供了两种解析 GPX 文件的方法:一旦你获得/创建了一个 GPXParser 对象(下面示例中的 mParser
),你就可以直接解析你的 GPX 文件
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
}
或者你可以解析一个远程文件:
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
}
}
});
欢迎投稿。
关于Android:需要帮助从 .GPX 文件解析数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10845532/
起亚, 我从 Strava 导出了我所有的 GPX 文件,所以我可以对它们进行一些分析,但我一直在试图弄清楚每个文件用于什么类型的事件。 例如,我的文件看起来像这样,其中 元素似乎定义了事件类型。
我正在开发 iOS 5 应用程序。 我想开发一个 GPX 解析器,但我想知道在我开始开发它之前是否已经开发了一个。 你知道有没有 Objective-c GPX 解析器吗? 最佳答案 看看: http
我正在尝试使用 writeOGR 创建点的 gpx 文件。 writeOGR() 将创建一个没有错误的 shp 文件,但如果我尝试编写 KML 或 GPX 文件,我会收到此错误。我在 Windows
我正在尝试在 Xcode 中模拟一条具有速度、纬度和经度信息的路径。 有一个站点生成相同的内容:http://www.bikehike.co.uk/mapview.php 我找到了一个 awk 脚本可
我正在使用 openlayers(用于 Web GIS 的 JavaScript API)开发一个 Web 测绘项目,我需要为用户提供一个选项,以从他们之前所在的坐标中获取 .gpx 导出。 我正在选
假设我有许多 .gpx 文件(这些文件包含来自 Garmin eTrex 的 GPX 航路点数据)。我想将它们以不同的名称加载到 R 中并对其进行操作。 我可以这样读取一个文件: library(ma
我想知道 GPX 赛道和路线文件之间的基本区别是什么 最佳答案 路线是一系列航点,它是您的导航计划。轨迹是您在尝试实现计划(路线)时实际遵循的记录路径。 作为 GPX 文件,路线和轨迹使用不同的 XM
我想为 IOS 实现一个应用程序。此应用程序应跟踪 gpx 文件中的路线。你能告诉我一些链接或开源项目吗?非常感谢 最佳答案 所以我想这是一个有点老的问题,但我在最近搜索 GPX 时发现了这个问题并且
我的 iOS 程序将创建一个 gpx 文件。这两者之间的正确格式是什么?是吗: 或者 New Track
我一直在四处寻找,但无法找到 GPX 文件中与“0”高程相对应的椭球体或大地水准面的标准。有标准吗?我是否只假设 WGS84 椭球体?或者,如果使用了不同的标准,是否有办法从文件中找出使用的标准?还是
我已经有一段时间对将 GPX 文件添加到 Iphone/iPad 项目有疑问了。GPX 文件到底包含什么以及它在模拟器上运行应用程序时如何帮助我们。 最佳答案 首先看一下this wiki site
我有一个需要构建的 Android 程序,它将一些 GPS 坐标导出到 gpx 文件。这是我到目前为止的代码。我正在寻找从位置管理器存储 GPS 坐标然后传递到 gpx 文件的最佳方法。 主 Acti
如何在 GPX 文件中发表评论? 我在谷歌上查过,这里没有运气。谢谢 ! 最佳答案 假设 GPX = GPS eXchange Format 它只是 XML,因此您只需要一个标准的 XML 注释:
我目前正在使用 DDMS 透视图通过 gpx 文件模拟 android 模拟器的运动。但是,我只能找到带有纬度/经度对的 gpx 文件,而不是速度、高度等。关于找到一个好的 gpx 文件的任何建议,其
如何轻松创建一个 GPX 文件来表示两点之间的轨迹(带有航路点)? 最佳答案 这Tool太棒了!设置位置或路线并下载 GPX 文件。不要忘记删除文件末尾的 .txt。 玩得开心:D 关于ios - 创
我按照教程学习解析 gpx 文件(位于我的原始文件夹中)中的数据,但出于某种原因,没有数据被解析到 NodeList 中。这是我的 XMLParser 类 package bry.Bicker.Oja
我有一个带有速度列的 Pandas 数据框,其中偶尔有噪音(数据来自 Garmin,代表运行期间捕获的数据)。 我正在尝试找到一种对相邻点进行平均的方法,但是当我遇到这样的事情时 9.11227344
我有一个文本文件,其中包含以逗号分隔的不同点的纬度和经度,如下所示。我想将它转换成 GPX 文件,这样我就可以使用它来将坐标从这个文件发送到我的模拟器。如何通过 java 类做到这一点?我的文本文件如
Wikipedia says GPX 文件的 MIME 类型是 application/gpx+xml。所以我使用了以下代码: startActivityForResult( new Inte
有没有一种方法可以在运行时以编程方式更改位置模拟器城市?例如,这将允许测试模拟伦敦或东京。 下图显示了如何手动切换位置(GPX 文件)。如何在应用程序运行时以编程方式实现此结果? 最佳答案 另一种设置
我是一名优秀的程序员,十分优秀!