title: Mapbox Navigation via Customised Routes
body: <p>So Mapbox provides an awesome Navigation SDK for Android, and what I have been trying to do is create my own routes, representing each point as a Feature in a Geojson file, and then passing them on to the MapMatching module to get directions that I can then pass to the Navigation Engine. </p>
  
  <p>My solution evolves into two main parts. The first one involves iterating through the points I want navigation to go through, by adding them as input to the .coordinates element of MapboxMapMatching.builder() and subsequently converting this to 
  .toDirectionRoute(); per Mapbox instructions and example here: <a href="https://www.mapbox.com/android-docs/java/examples/use-map-matching/" rel="nofollow noreferrer">https://www.mapbox.com/android-docs/java/examples/use-map-matching/</a></p>
  
  <pre><code>private void getWaypointRoute(List&lt;Point&gt; features) {
  
      originPosition = features.get(0);
      destinationPosition = features.get(features.size() - 1);
  
      MapboxMapMatching.builder()
              .accessToken(Mapbox.getAccessToken())
              .coordinates(features)
              .steps(true) // Setting this will determine whether to return steps and turn-by-turn instructions.
              .voiceInstructions(true)
              .bannerInstructions(true)
              .profile(DirectionsCriteria.PROFILE_DRIVING)
              .build().enqueueCall(new Callback&lt;MapMatchingResponse&gt;() {
  
          @Override
          public void onResponse(Call&lt;MapMatchingResponse&gt; call, Response&lt;MapMatchingResponse&gt; response) {
              if (response.body() == null) {
                  Log.e(TAG, "Map matching has failed.");
                  return;
              }
  
              if (response.isSuccessful()) {
                  currentRoute = response.body().matchings().get(0).toDirectionRoute();
  </code></pre>
  
  <p>The second bit involves just passing 'currentRoute' to the NavigationLauncher as shown below:</p>
  
  <pre><code>                NavigationLauncherOptions options = NavigationLauncherOptions.builder()
                          .origin(origin)
                          .destination(destination)
                          .directionsRoute(currentRoute)
                          .shouldSimulateRoute(simulateRoute)
                          .enableOffRouteDetection(false)
                          .build();
  
                  // Call this method with Context from within an Activity
                  NavigationLauncher.startNavigation(MainActivity.this, options);
  </code></pre>
  
  <p>An example of the route can be seen here <a href="https://i.stack.imgur.com/LbXWx.jpg" rel="nofollow noreferrer">Android Simulator Snapshot with Route </a>. Each point across the route, is an intersection, and corresponds to a feature in my GeoJson file. The problem becomes when I launch the navigation. Every time, either in the simulator or on a real device, each point is interpreted as a destination so the voice command goes 'You have reached your first (second, third etc) destination'. I find this annoying as I would like to have a single route with a destination and that's it. I would just like to have this points so I have my own custom path, instead of the shortest path typically returned by routing applications. I try to avoid the problem by setting voiceInstructions off but then the system goes bananans and the navigation screen moves to lat, lng (0,0) which is pretty much somewhere West of Africa. Any help on how I could resolve this it would be greatly appreciated and I would be happy to buy a beer or two for the person that provides the right answer. I have reached out to Mapbox Support as well but we have not found an answer to the problem so I asked them to escalate it internally within their engineering team, as I believe, although the problem I am solving is not uncommon, it is still not very much tested by developers. Cheers!</p>