如何在我的谷歌上嵌入转弯导航

时间:2012-12-13 12:08:58

标签: android google-maps

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

3 个答案:

答案 0 :(得分:3)

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

有很多优秀的SDK提供商:

  • skobbler(现在的Telenav)有一个SDK,可以渲染地图和在Android手机上显示转弯导航。它还支持离线模式。查看更多here
  • OsmSharp也可以进行地图渲染并轮流导航。您可以从github
  • 中提取代码
  • MapQuest对Android有一个很好的map & routing engine。我认为您也可以将他们的路由服务与Mapbox地图一起使用(请参阅this作为起点)。我不认为他们可以做离线模式
  • Cloudmade有一个navigation SDK Android版。他们的文档显示了如何实现它,但我找不到快速下载SDK& amp;样本项目

作为参考,您会看到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);
相关问题