Vehicle

VERSION 0.54.0

The Navigation SDK for iOS is only available upon request. Contact us to get started.

The Vehicle module offers a VehicleProvider interface that is responsible for the control, access, and listening to changes in the vehicle state.

The integrator can choose to provide its implementation of the VehicleProvider or use the TomTom default thread-safe implementation.

The TomTom implementation can be obtained via the VehicleProviderFactory.

VehicleProviderFactory allows the user to pass a custom vehicle object for initialization of the VehicleProvider. If no vehicle object is provided, a non-commercial car with a combustion engine is used by default.

When an instance of VehicleProvider is created, it can be injected into other TomTom modules that depend on it, e.g., Navigation.

Setting the initial vehicle profile, then switching to a different vehicle

The following code snippet shows how to set the initial profile as an electric engine car and later switch to a bicycle, another vehicle type.

1let chargeLevel = try ElectricEngine.ChargeLevel(
2 currentCharge: Measurement.tt.kilowattHours(30.0),
3 maxCharge: Measurement.tt.kilowattHours(60.0)
4)
5let electricEngine = ElectricEngine(chargeLevel: chargeLevel)
6let electricCar = Car(electricEngine: electricEngine)
7var vehicleProvider = VehicleProviderFactory.create(vehicle: electricCar)
8
9// Switch to a bicycle
10let bicycle = Bicycle()
11vehicleProvider.vehicle = bicycle

Updating the vehicle profile

This updates the listed VehiclePropertys in the current vehicle profile. If a property, which is not PropertyID.maxSpeed or PropertyID.isCommercial, was not previously set, it throws a VehicleError. PropertyID.maxSpeed can be updated for every vehicle type. PropertyID.isCommercial can be updated for a motorized vehicle type.

1let updatedCurrentChargeProperty = Measurement.tt.kilowattHours(25.0)
2let updatedElectricEngineProperties: [ElectricEngineProperty] = [.currentCharge(updatedCurrentChargeProperty)]
3let updatedVehicleProperties = VehicleProperty.electricEngine(updatedElectricEngineProperties)
4
5try vehicleProvider.updateVehicleProperties([updatedVehicleProperties])

Snapshot of the current vehicle profile

The following code snippet shows how to get the snapshot of the current vehicle’s state:

let currentVehicleSnapshot = vehicleProvider.vehicle

Listening to vehicle updates

The integrator can listen for the specific changes of the VehiclePropertys or every vehicle state change. If the integrator attempts to add the same observer twice, the VehicleError is thrown, regardless of how it was added.

Vehicle state changes

The following code snippet shows how to add an observer whose method will be called once the vehicle’s state changes:

1class MyVehicleUpdateObserver: VehicleUpdateObserver {
2 func didUpdateVehicle(_ vehicle: any Vehicle, updatedPropertyIDs: [PropertyID]) {
3 // YOUR CODE GOES HERE
4 }
5}
6let myVehicleUpdateObserver = MyVehicleUpdateObserver()
7try vehicleProvider.addVehicleUpdateObserver(myVehicleUpdateObserver)

Next steps

Since you have learned how to setup a vehicle provider, here are recommendations for the next step: