0

我想在我的 android 应用程序中嵌入轮流导航。请给我一个教程或如何做到这一点的想法。提前谢谢。

4

3 回答 3

3

如果您不固定使用谷歌地图,您可以使用基于 OpenStreetMap(地图的维基百科版本)的 SDK

有几个不错的 SDK 提供者:

  • skobbler(现为 Telenav)有一个 SDK,它能够在您的 Android 手机上通过轮流导航来渲染地图和显示轮流。它还支持离线模式。在这里查看更多
  • OsmSharp还进行地图渲染和轮流导航。你可以从github拉取他们的代码
  • MapQuest有一个不错的 Android地图和路由引擎。我认为您也可以将他们的路由服务与 Mapbox 地图一起使用(将此作为起点)。我不认为他们可以做离线模式
  • Cloudmade有一个适用于 Android 的导航 SDK。他们的文档显示了它是如何实现的,但我找不到快速下载 SDK 和示例项目的方法

作为参考,您可以查看 OSM框架列表

于 2014-02-25T07:59:43.657 回答
3

我认为没有办法将转向指令嵌入到我的应用程序中,但我完全错了。Google Maps API V2 实际上确实提供了路线指示。查看 Google 的文档

我使用这个库中给出的代码来获取基本的路由信息​​。然后,我添加了以下方法来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 换行符连接起来。如果您有兴趣,该代码就在这里。

于 2014-07-16T16:34:28.210 回答
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);
于 2012-12-13T12:23:21.303 回答