【发布时间】:2012-12-13 12:08:58
【问题描述】:
我想在我的 android 应用程序中嵌入轮流导航。请给我一个教程或如何做到这一点的想法。提前谢谢。
【问题讨论】:
-
嗨,你实现了吗?请帮助我,我必须像这样实施同样的操作
标签: android google-maps
我想在我的 android 应用程序中嵌入轮流导航。请给我一个教程或如何做到这一点的想法。提前谢谢。
【问题讨论】:
标签: android google-maps
如果您不固定使用谷歌地图,您可以使用基于 OpenStreetMap(地图的维基百科版本)的 SDK
有几个不错的 SDK 提供者:
作为参考,您可以看到 OSM list of frameworks
【讨论】:
我认为没有办法在我的应用程序中嵌入转向指令,但我完全错了。 Google Maps API V2 实际上确实提供了路线指示。查看 Google 的documentation。
我使用this library 中给出的代码来获取基本的路由信息。然后,我将以下方法添加到 GoogleDirection.java 以返回转弯指令列表:
// getInstructions returns a list of step-by-step instruction Strings with HTML formatting
public ArrayList<String> getInstructions(Document doc) {
ArrayList<String > instructions = new ArrayList<String>();
NodeList stepNodes = doc.getElementsByTagName("step");
if (stepNodes.getLength() > 0) {
for (int i = 0; i < stepNodes.getLength(); i++) {
Node currentStepNode = stepNodes.item(i);
NodeList currentStepNodeChildren = currentStepNode.getChildNodes();
Node currentStepInstruction = currentStepNodeChildren.item(getNodeIndex(currentStepNodeChildren, "html_instructions"));
instructions.add(currentStepInstruction.getTextContent());
}
}
return instructions;
}
这种方法不提供实时更新,告诉您何时到达新的转折点,但它运作良好并且可以满足我的需求。我将getInstructions 方法与instructionsToString 辅助方法一起使用,它将指令与HTML 换行符连接起来。如果您有兴趣,该代码是here。
【讨论】:
您可以在 Activity 中使用此代码:
double latitudeDestination = 52.377028; // or some other location
double longitudeDestination = 4.892421; // or some other location
String requestedMode = "walking" // or bike or car
String mode = "";
if(requestedMode.equals("walking")) {
mode = "&mode=w";
} else if(requestedMode.equals("bike")) {
mode = "&mode=b";
} else if(requestedMode.equals("car")) {
mode = "&mode=c";
}
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse(String.format("google.navigation:ll=%s,%s%s", latitudeDestination, longitudeDestination, mode)));
startActivity(intent);
【讨论】: