Navigation with Waypoints

This is the same idea as our earlier navigation example , but this one demonstrates how to navigate a route with many waypoints (rather than just a single origin and destination).

First off, you need to setup a route request according to the coordinates that you're going to navigate to.

TGRouteRequest routeRequest = new TGRouteRequest.Builder()
               .addCoordinate(34.119190d, -118.300348d) //Griffith Observatory (origin)
               .addCoordinate(34.101558d, -118.340944d) //Grauman's Chinese Theatre (mid)
               .addCoordinate(34.102078d, -118.334236d) //Hollywood Walk of Fame (mid)
               .addCoordinate(34.011441d, -118.494932d) //Santa Monica Pier (destination)
               .build();

If you're testing at your desk, you'll probably want to simulate your location, as before. However, skip this block if you want to test in the real world.

LatLng simulatedCurrentLocation = routeRequest.getWayPoints().get(0).getCoordinate(); // Start from the first waypoint
boolean simulate = true;
boolean clickToUpdate = false;

TallyGo.getInstance().enableSimulation(simulate, clickToUpdate, simulatedCurrentLocation);

Now you can take two different approaches:

  1. To launch the preview screen to get a preview of the route with all the waypoints, from which you can then begin turn-by-turn navigation.
    TGLauncher.startPreview(CONTEXT, routeRequest);
  2. Or to launch the turn-by-turn navigation directly without any route preview.
    TGLauncher.startTurnByTurn(CONTEXT, routeRequest);
Check out the Android Reference App to see this example in action.