This example computes a route for a truck. The route respects the lorry transport mode and a truck profile - the vehicle's mass, height, length, width, axle load and maximum speed - so the result avoids roads the truck cannot legally or physically use (low bridges, weight-limited roads, narrow streets, and similar). The computed alternatives are drawn on the map with distance/time bubbles, and a settings panel lets the user change the truck's characteristics and recompute.
On success the routes (there may be several alternatives between departure and destination) are drawn with presentRoutes; displayBubble = true adds the distance/time bubble seen on each route, and edgeAreaInsets fits them clear of the toolbar and system bars. The settings button is then revealed so the truck profile can be edited.
Once the worldwide road map is downloaded and up to date, the departure/destination waypoints and a default truck profile are set up, and the route is calculated. Two things make the routing truck-aware: setting preferences.transportMode to ERouteTransportMode.Lorry, and assigning preferences.truckProfile. The trip runs from London to Paris.
calculateRoute returns synchronously whether the calculation could be started; on a start failure onCompleted never fires, so that case is reported in a dialog here.
TruckProfile is expressed in the SDK's native units - kilograms, centimetres and metres per second - while the UI works in tonnes, metres and km/h. The example centralizes the conversion factors in an ETruckProfileUnitConverters enum, and each editable setting in ETruckProfileSettings knows both its converter and how to read its raw value back from a TruckProfile. Multiplying a display value by converter.unit gives the native value; dividing does the reverse.
Once the map view exists, a touch listener lets the user pick one of the alternatives. The touch point is forwarded to the map as cursorScreenPosition, and cursorSelectionRoutes returns the routes under it. The first hit becomes the main route (drawn highlighted), and the camera re-centers on the whole set with centerOnRoutes.
Tapping the settings button opens a dialog backed by a RecyclerView. Each row is a labelled slider for one truck attribute (weight, height, length, width, axle weight, maximum speed), seeded with default ranges by getInitialDataSet.
// ... height, length, width, axle weight, and an int-valued max speed slider
}
When the dialog is shown, each slider is initialized from the current preferencesTruckProfile: the adapter reads the raw value with the setting's getValue and converts it to the display unit by dividing by converter.unit.
The dialog's Save button calls onSaveButtonClicked, which reads each slider, converts the display values back to native units, builds a new TruckProfile, assigns it to the routing preferences (again with transportMode = Lorry), clears the previously drawn routes, and recomputes. The new route then arrives through the same onCompleted callback and is presented as before.