user1761098
user1761098

Reputation: 57

how to embed Turn by turn navigation on my google

I want to embed turn by turn navigation in my android application.please give me a tutorial or an idea for how to do this.thanks in advance.

Upvotes: 0

Views: 6291

Answers (3)

VinceFior
VinceFior

Reputation: 1279

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.

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;
}

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.

Upvotes: 3

Ando
Ando

Reputation: 11439

If you are not fixed on using google maps you can use an SDK based on OpenStreetMap (the Wikipedia version of maps)

There are a couple of good SDK providers out there:

  • skobbler (now Telenav) has an SDK which is able to render maps & display turn by turn navigation on your Android phone. It also supports offline mode. See more here
  • OsmSharp also does map rendering and turn by turn navigation. You can pull their code from github
  • MapQuest has a nice map & routing engine for Android. I think you could also use their routing service with Mapbox maps (see this as a starting point). I don't think they can do offline mode
  • Cloudmade has a navigation SDK for Android. Their documentation shows how it can be achieved but I couldn't find a way of quickly downloading the SDK & sample projects

As a reference you see the OSM list of frameworks

Upvotes: 3

Wouter Vegter
Wouter Vegter

Reputation: 1113

you can use this code in your 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);

Upvotes: 1

Related Questions