本文介绍了如何嵌入在我的谷歌上翻转导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

推荐答案

我想在我的android应用程序中依次嵌入轮流导航。请给我一个关于如何做到这一点的教程或想法。解决方案

解决方案

我认为没有办法将turn-by-turn指令嵌入到我的应用程序中,但我完全错了。 Google Maps API V2实际上提供了逐个转向的说明。查看Google的。

I thought that there was no way to embed turn-by-turn instructions into my application, but I was totally wrong. The Google Maps API V2 actually does offer turn-by-turn instructions. Check out Google's documentation.

我使用了中给出的代码来获取基本的路由信息​​。然后我将以下方法添加到 GoogleDirection.java 中,以返回转向指令列表:

I used the code given in this library to get basic routing information. I then added the following method to GoogleDirection.java to return a list of turn-by-turn instructions:

// 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 helper方法一起使用,该方法将指令与HTML换行符连接起来。如果您有兴趣,该代码为。

This approach doesn't offer real-time updates telling you when you've reached a new turn, but it works well and serves my needs. I use my getInstructions method with an instructionsToString helper method, which concatenates the instructions with an HTML line break. That code is here if you're interested.

这篇关于如何嵌入在我的谷歌上翻转导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 21:55