我想在我的android应用程序中嵌入转弯导航。请给我一个教程或想法如何做到这一点。提前谢谢。
答案 0 :(得分:3)
如果您没有使用谷歌地图,您可以使用基于OpenStreetMap的SDK(维基百科版本的地图)
有很多优秀的SDK提供商:
作为参考,您会看到OSM list of frameworks
答案 1 :(得分:3)
我认为没有办法将转弯指令嵌入到我的应用程序中,但我完全错了。 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。
答案 2 :(得分:1)
您可以在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);