Skip to content

Vehicle Profile

Following example will guide you through setting up the MapTrip SDK for normal truck routing.

The MapTrip SDK can be used for car and truck routing. Therefore, it is important to set the right speed profile and vehicle attributes. Consequently, the MapTrip SDK provides different VehicleProfiles as list by calling VehicleProfile.getVehicleProfileIterator() or VehicleProfile.getVehicleProfileIteratorByName(name).

At first, you will need to get the right VehicleProfile based on the profile name for your purposes. You will usually selected between car (types_fast.txt) or truck (types_truck_highway.txt).

1
2
3
4
5
6
7
8
val iterator = VehicleProfile.getVehicleProfileIteratorByName("types_truck_highway.txt")

val truckProfile: VehicleProfile? = if (iterator.hasNext()) {
    iterator.next()
} else {
    Log.e("VehicleProfile", "Profile not found: types_truck_highway.txt")
    null
}

Next, you want to customize vehicle attributes, e.g.:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
truckProfile?.apply {
    setVehicleHeight(4.0)      // meters
    setVehicleWidth(2.5)       // meters
    setVehicleLength(18.0)     // meters

    setVehicleTotalWeight(20_000)   // kg
    setVehicleWeightPerAxle(10_000) // kg
    setVehicleNumAxles(2)
    setVehicleNumTrailers(1)

    setVehicleLoadingTRC(VehicleLoadTrc.C) // Tunnel Restriction Code

    setVehicleAttributesEnabled(true) // enable attributes
}

Finally, activate the profile:

1
2
3
4
5
6
7
8
truckProfile?.let {
    val activationError = it.setAsActiveProfile()
    if (activationError != ApiError.OK) {
        Log.e("VehicleProfile", "Failed to set active profile: $activationError")
    } else {
        Log.i("VehicleProfile", "Activated profile: ${it.profileName}")
    }
}

Overall you can use the speed profile independent of vehicle attributes. This comes in handy if you only care about the right speed profile or you want to add attributes to a car, e.g. to serve as sprinter.

In summary, make sure that you

  • Use getVehicleProfileIteratorByName("types_truck_highway.txt") to directly fetch the desired profile.
  • Use setter methods (setVehicleHeight, setVehicleTotalWeight, etc.) to customize.
  • Call setVehicleAttributesEnabled(true) if you want to use it.
  • Call setAsActiveProfile() to activate it for routing.