【发布时间】:2014-08-01 21:41:50
【问题描述】:
我已经在我的 android APP 中实现了 google map api 功能。 谷歌地图 api 给了我一个正确的路线(方向),但它给出了两个端点之间的错误距离和时间。
我已经在 android 中以 XML 格式实现了这个 google map api。 以下是我用来获取两个端点之间距离的代码。 (我使用的是“驾驶”模式)。
public String getDistanceText(Document doc) {
NodeList nl1 = doc.getElementsByTagName("distance");
Node node1 = nl1.item(0);
NodeList nl2 = node1.getChildNodes();
Node node2 = nl2.item(getNodeIndex(nl2, "text"));
Log.i("DistanceText", node2.getTextContent());
return node2.getTextContent();
}
public int getDistanceValue(Document doc) {
NodeList nl1 = doc.getElementsByTagName("distance");
Node node1 = nl1.item(0);
NodeList nl2 = node1.getChildNodes();
Node node2 = nl2.item(getNodeIndex(nl2, "value"));
Log.i("DistanceValue", node2.getTextContent());
return Integer.parseInt(node2.getTextContent());
}
以下是获取两个端点之间持续时间的代码:
public String getDurationText(Document doc) {
NodeList nl1 = doc.getElementsByTagName("duration");
Node node1 = nl1.item(0);
NodeList nl2 = node1.getChildNodes();
Node node2 = nl2.item(getNodeIndex(nl2, "text"));
Log.i("DurationText", node2.getTextContent());
return node2.getTextContent();
}
public int getDurationValue(Document doc) {
NodeList nl1 = doc.getElementsByTagName("duration");
Node node1 = nl1.item(0);
NodeList nl2 = node1.getChildNodes();
Node node2 = nl2.item(getNodeIndex(nl2, "value"));
Log.i("DurationValue", node2.getTextContent());
return Integer.parseInt(node2.getTextContent());
}
我在这里做错了什么?
任何帮助将不胜感激。
【问题讨论】:
-
已经回答:[Link][1] [1]:stackoverflow.com/questions/14394366/…
标签: android google-maps google-directions-api