Direction Widget¶
A ready to use Fragment to show the Routes in an Android platform. It offers the following basic functionalities:
- Takes support of Mappls Place search for searching locations of origin, destinations and via points.
- It allows to use origin and destinations in Mappls digital address (semicolon separated) mapplsPin or WGS 84 geographical coordinates both.
- The ability to set the vehicle profile like driving, and biking.
- Easily set the resource for traffic and ETA information.
For more details, please contact apisupport@mappls.com.
Add the dependency¶
Add below dependency in your app-level build.gradle
Kotlin (build.gradle.kts)¶
// When using the BoM, you don't specify versions in Mappls library dependencies
implementation("com.mappls.sdk:direction-ui")
//Or Add Dependency with Version
implementation("com.mappls.sdk:direction-ui:3.0.0")
Groovy (build.gradle)¶
// When using the BoM, you don't specify versions in Mappls library dependencies
implementation 'com.mappls.sdk:direction-ui'
//Or Add Dependency with Version
implementation("com.mappls.sdk:direction-ui:3.0.0")
Add Direction Widget¶
Kotlin¶
val directionFragment: DirectionFragment = DirectionFragment.newInstance()
supportFragmentManager.beginTransaction().add(R.id.fragment_container, directionFragment, DirectionFragment::class.java.simpleName)
.commit()
//OR
val directionFragment: DirectionFragment = DirectionFragment.newInstance(directionOptions)
supportFragmentManager.beginTransaction().add(R.id.fragment_container, placeAutocompleteFragment, PlaceAutocompleteFragment::class.java.simpleName)
.commit()
Java¶
DirectionFragment directionFragment = DirectionFragment.newInstance();
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, directionFragment, DirectionFragment.class.getSimpleName())
.commit();
//OR
DirectionFragment directionFragment = DirectionFragment.newInstance(directionOptions);
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, directionFragment, DirectionFragment.class.getSimpleName())
.commit();
You can use DirectionOptions
to set the properties of direction widget:
resource(String)
: Below are the available resource:- DirectionsCriteria.RESOURCE_ROUTE (Default): to calculate a route & its duration without considering traffic conditions.
- DirectionsCriteria.RESOURCE_ROUTE_ETA: get the updated duration of a route considering live traffic; Applicable for India only "region=ind" and "rtype=1" is not supported. This is different from route_traffic; since this doesn't search for a route considering traffic, it only applies delays to the default route.
- DirectionsCriteria.RESOURCE_ROUTE_TRAFFIC:
to search for routes considering live traffic; Applicable for India only “region=ind” and “rtype=1” is not supported
showAlternative(Boolean)
: Show alternative routes.profile(String)
: Below are the available profile:- DirectionsCriteria.PROFILE_DRIVING (Default):Meant for car routing
- DirectionsCriteria.PROFILE_WALKING: Meant for pedestrian routing. Routing with this profile is restricted to route_adv only. region & rtype request parameters are not supported in pedestrian routing
- DirectionsCriteria.PROFILE_BIKING:Meant for two-wheeler routing. Routing with this profile is restricted to route_adv only. region & rtype request parameters are not supported in two-wheeler routing.
- DirectionsCriteria.PROFILE_TRUCKING:Meant for Truck routing. Routing with this profile is restricted to route_adv only. region & rtype request parameters are not supported in truck routing.
overview(String)
: Add overview geometry either full, simplified according to highest zoom level it could be display on, or not at all. Below are the available value:- DirectionsCriteria.OVERVIEW_FULL
- DirectionsCriteria.OVERVIEW_FALSE
- DirectionsCriteria.OVERVIEW_SIMPLIFIED
steps(Boolean)
: Return route steps for each route leg. Possible values are true/false. By default it will be used as false.excludes(List<String>)
: Additive list of road classes to avoid, order does not matter. Below are the available value:- DirectionsCriteria.EXCLUDE_FERRY
- DirectionsCriteria.EXCLUDE_MOTORWAY
- DirectionsCriteria.EXCLUDE_TOLL
showStartNavigation(Boolean)
: To show the Start Navigation button if the origin is current location.showDefaultMap(Boolean)
: To add the option to show default mapdestination(DirectionPoint)
: You can useDirectionPoint
to pass the destination in direction widget:setDirection(Point, String, String)
: It takes coordinate, place name and place addresssetDirection(String, String, String)
: It takes mappls pin, place name and place address
origin(DirectionPoint)
: You can useDirectionPoint
to pass the origin in direction widget:setDirection(Point, String, String)
: It takes coordinate, place name and place addresssetDirection(String, String, String)
: It takes mappls pin, place name and place address
searchPlaceOption(PlaceOptions)
: To set the properties of search widget.showAddWaypointOption(Boolean)
: To show/hide add waypoint functionality.showTripCostSummary(Boolean)
: To show/hide trip cost summary this functionality only works with DirectionsCriteria.RESOURCE_ROUTE_ETAshowRouteReportSummary(Boolean)
: To show/hide route report summary.showRouteReportSummaryOnMap(Boolean)
: To show/hide Route Report summary on Map.showProfileOption(Boolean)
: To show the profile switch option.theme(Integer)
: To change the theme of the UI. Below are the available value:DirectionOptions.THEME_DEFAULT
DirectionOptions.THEME_DAY
(Default)DirectionOptions.THEME_NIGHT
Additional Parameter - Search Along The Route¶
searchAlongRoute(Boolean)
: An easy, ready to use UI has been introduced to search pois Along the route with default categories list.Default is true.
To access this parameter , please contact API Support This parameter takes the encoded route along which POIs will be searched.
This parameter is further having configurable options listed below.
- alongRouteBuffer (Integer) : 200, // Buffer of the road. Minimum value is 25m, maximum is 1000m and default is 25m
CategoryCode: This class is used to set the information for the poi categories to show in Widget. It contains the following properties in constructor:
- category (String): Name of the category that display on a view
- icon(Integer): To show icon of category
- categoryCode (List
): List of category codes - markerIcon (Integer): Marker icon to display on a map
- isSelected (Boolean): To set the category is selected or not.
Kotlin¶
val categoryCodes: MutableList<CategoryCode?> = ArrayList<CategoryCode?>()
val coffeeCatgories: MutableList<String?> = ArrayList<String?>()
coffeeCatgories.add("FODCOF")
categoryCodes.add(
CategoryCode(
"Coffee",
R.drawable.icon_coffee,
coffeeCatgories,
R.drawable.ic_map_coffee
)
)
val directionOptions = DirectionOptions.builder()
.alongRouteBuffer(300)
.searchAlongRoute(true)
.build()
directionFragment = DirectionFragment.newInstance(directionOptions)
directionFragment.setCategoryCodes(categoryCodes)
addFragment(R.id.container, directionFragment, false, false)
Java¶
List<CategoryCode> categoryCodes = new ArrayList<>();
List<String> coffeeCatgories = new ArrayList<>();
coffeeCatgories.add("FODCOF");
categoryCodes.add(new CategoryCode("Coffee", R.drawable.icon_coffee,coffeeCatgories, R.drawable.ic_map_coffee));
DirectionOptions directionOptions = DirectionOptions.builder()
.alongRouteBuffer(300)
.searchAlongRoute(true)
.build();
directionFragment = DirectionFragment.newInstance(directionOptions);
directionFragment.setCategoryCodes(categoryCodes);
addFragment(R.id.container, directionFragment, false, false);
To pass the MapView¶
Kotlin¶
directionFragment.provideMapView(mapView)
Java¶
directionFragment.provideMapView(MapView);
Callbacks getting from Direction Fagment¶
Implement from DirectionCallback interface:
Kotlin¶
directionFragment.setDirectionCallback(object : DirectionCallback {
override fun onCancel() {
//on Click of back button
}
override fun onStartNavigation(
origin: DirectionPoint?,
destination: DirectionPoint?,
waypoints: MutableList<DirectionPoint?>?,
directionsResponse: DirectionsResponse?,
selectedIndex: Int
) {
//Get the origin, destination, waypoints, directionsResponse and the selected Index
}
})
Java¶
directionFragment.setDirectionCallback(new DirectionCallback() {
@Override
public void onCancel() {
//on Click of back button
}
@Override
public void onStartNavigation(DirectionPoint origin, DirectionPoint destination, List<DirectionPoint> waypoints, DirectionsResponse directionsResponse, int selectedIndex) {
//Get the origin, destination, waypoints, directionsResponse and the selected Index
}
});
For any queries and support, please contact:
Email us at apisupport@mappls.com
Support
Need support? contact us!