【问题标题】:how to embed Turn by turn navigation on my google如何在我的谷歌上嵌入转弯导航
【发布时间】:2012-12-13 12:08:58
【问题描述】:

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

【问题讨论】:

  • 嗨,你实现了吗?请帮助我,我必须像这样实施同样的操作

标签: android google-maps


【解决方案1】:

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

有几个不错的 SDK 提供者:

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

作为参考,您可以看到 OSM list of frameworks

【讨论】:

    【解决方案2】:

    我认为没有办法在我的应用程序中嵌入转向指令,但我完全错了。 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

    【讨论】:

      【解决方案3】:

      您可以在 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);
      

      【讨论】:

      • 实际上,这会触发 Google 的导航应用。作者想在他的应用程序中逐个嵌入。
      • @Bolhoso,我同意。我看到了一些这样的帖子,并得出结论认为提问者想要的是不可能的,但事实证明这是完全可能的。查看我的答案以获取嵌入式逐向说明。 :)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      • 2015-11-28
      • 1970-01-01
      • 1970-01-01
      • 2022-06-12
      • 2019-05-08
      • 2013-10-01
      相关资源
      最近更新 更多