Last updated
Last updated
This tutorial will show how to work with the route model returned from a directions service call. It will also show how you can utilize interactions between the route rendering on the map, and text-based instructions showed in another view.
This tutorial will be based off the MapsIndoors Samples example found here: .
An example of the view XML file for the WayfindingFragment
this guide will use can be found here: .
First, create variables for MPLocation
and MPRoute
objects to use later in describing wayfinding. Also create a Variable for MPDirectionsRenderer
so we can control rendering through changes in the ViewPager
.
Next step we will create the Fragment
that will contain a short description of each Leg of the route inside the ViewPager
An example of the view XML file for the RouteLegFragment
, that this guide will use, can be found here: .
We will start by adding the code inside the WayfindingFragment
.
First, start by changing the code inside onCreateView
.
Next we will create FragmentStateAdapter
that will be used on the ViewPager
to contain RouteLegFragments
Let's create a method to textually describe each Leg. This method creates a string that takes the first and last step of the next leg to create a description for the user on what to do at the end of the currently shown leg. You will also create a method to get a list of the different highway types the route can give the user. These are found as enums through the MPHighway
class in the MapsIndoors SDK.
Now, lets create the RouteLegFragment
to give context for the Legs in the WayfindingFragment
You must also update the onViewCreated
method to use the new views added earlier in the tutorial.
Now you have the revised UI for providing the user with a more explanatory route description when navigating. Now it needs to be rendered onto the map.
We will create a method named getRoute that queries a route between two location, we know exist on the current solution. When we receive the route we will assign the route to the fragment as well as calling setRoute
on the MPDirectionsRenderer
with the received Route. We will also notify the ViewPager that the route is updated with notifyDataSetChanged
.
To change the routing when swapping between tabs on the viewpager, use the call back that we added further up inside the onViewCreated
of NavigationFragment
.
You should now have a Fragment with a map that has a route rendered on it. With descriptions of each Leg of the Route inside a ViewPager that will display the Leg related to the page that is viewed.
The full working example can be found here: .
Android v4