3

我这里有问题。我想测试我的解析器结果。

我有一个从请求到谷歌地图的 kml 文件。这是我的 KML 文档

<LineString>
    <coordinates>
        106.826200,-6.297500,0.000000 
        106.826220,-6.297260,0.000000 
        106.826380,-6.297050,0.000000 
        106.826900,-6.296710,0.000000 
        106.827120,-6.296640,0.000000 
        106.827120,-6.296640,0.000000 
        106.827170,-6.296510,0.000000 
        106.827140,-6.296370,0.000000 
        106.827140,-6.296370,0.000000 
        106.826210,-6.295840,0.000000 
        106.824970,-6.295220,0.000000 
        106.823550,-6.294580,0.000000 
        106.822690,-6.293830,0.000000 
        106.822860,-6.293800,0.000000 
        106.823820,-6.294160,0.000000 
        106.825240,-6.294830,0.000000 
        106.830400,-6.297550,0.000000 
        106.831360,-6.298100,0.000000 
        106.885600,-6.293860,0.000000 
    </coordinates>
</LineString>

这是我的代码:

NodeList nl = doc.getElementsByTagName("LineString");
        for(int s = 0; s < nl.getLength(); s++){
            Node rootNode = nl.item(s);
            NodeList configItems = rootNode.getChildNodes();
            for(int x = 0; x < configItems.getLength(); x++){
                Node lineStringNode = configItems.item(x);
                NodeList path = lineStringNode.getChildNodes();
                pathConent = path.item(0).getNodeValue();
            }
        }

解析器成功,我可以在谷歌地图上绘制路线。但现在我想知道它是如何工作的,所以我想将坐标打印到 TextView。这是我的新代码:

NodeList nl = doc.getElementsByTagName("LineString");
        for(int s = 0; s < nl.getLength(); s++){
            Node rootNode = nl.item(s);
            NodeList configItems = rootNode.getChildNodes();
            for(int x = 0; x < configItems.getLength(); x++){
                Node lineStringNode = configItems.item(x);
                NodeList path = lineStringNode.getChildNodes();
                pathConent = path.item(0).getNodeValue();
            }
        }
    String[] tempContent = pathConent.split(" ");
            for (int i = 0; i < tempContent.length; i++){
                koor.setText("Latitude, Longitude:\n" + tempContent[i] + "\n");
            }

但是为什么在我的 TextView 中我只有第一个坐标(106.826200,-6.297500,0.000000)。你能帮我解决我的问题吗?

谢谢,我真的很抱歉我的英语>_<

4

1 回答 1

2

采用

    String[] tempContent = pathConent.split(" ");
    koor.setText("");
    for (int i = 0; i < tempContent.length; i++){
        koor.append("Latitude, Longitude:\n" + tempContent[i] + "\n");
    }

代替

String[] tempContent = pathConent.split(" ");
        for (int i = 0; i < tempContent.length; i++){
            koor.setText("Latitude, Longitude:\n" + tempContent[i] + "\n");
        }
于 2012-05-15T15:31:26.103 回答