# Odometer

{% hint style="info" %}
Methods presented in this part are available in the `DriveKitVehicle` class
{% endhint %}

## Synchronize vehicle's odometer

You can retrieve the vehicle’s odometer data from the DriveQuant servers by calling the following method:

```swift
func getOdometer(
	vehicleId: String, 
	type: DKVehicleSynchronizationType = .defaultSync, 
	completionHandler: @escaping (DKOdometerSyncStatus, DKVehicleOdometer?, [DKVehicleOdometerHistory]?) -> Void
)
```

This method have the following parameters:

<table><thead><tr><th width="165.33333333333331">Name</th><th width="206">Type</th><th>Description</th></tr></thead><tbody><tr><td>vehicleId</td><td>String</td><td>The vehicle for which you want to get the odometer’s data</td></tr><tr><td>type</td><td>SynchronizationType</td><td><p>Can be <code>defaultSync</code> or <code>cache</code>.</p><p>- <code>defaultSync</code> will synchronize the vehicle’s odometer by calling the DriveQuant servers</p><p>- <code>cache</code> will retrieve the odometer data already synchronized in the local database.</p></td></tr></tbody></table>

[DKOdometerSyncStatus](https://docs.drivequant.com/vehicle/references-ios#dkodometersyncstatus), [DKVehicleOdometer](https://docs.drivequant.com/vehicle/references-ios#dkvehicleodometer) and [DKVehicleOdometerHistory](https://docs.drivequant.com/vehicle/references-ios#dkvehicleodometerhistory) models are described in the References part.

## **Retrieve local vehicle’s odometer data**

You can retrieve the vehicle’s odometer data stored in the DriveKit local database by calling the previous method but with the type parameter to `cache`.

## **Add odometer history**

You can add a new entry to a vehicle’s odometer by calling the following method:

```swift
func addOdometerHistory(
    vehicleId: String,
    distance: Double,
    completionHandler: @escaping (DKOdometerAddHistoryStatus, DKVehicleOdometer?, [DKVehicleOdometerHistory]?) -> Void
)
```

This method have the following parameters:

| Name      | Type   | Description                                               |
| --------- | ------ | --------------------------------------------------------- |
| vehicleId | String | The vehicle id for which you want to add an history entry |
| distance  | Double | The distance in km you want to set                        |

[DKOdometerAddHistoryStatus](https://docs.drivequant.com/vehicle/references-ios#dkodometeraddhistorystatus), [DKVehicleOdometer](https://docs.drivequant.com/vehicle/references-ios#dkvehicleodometer) and [DKVehicleOdometerHistory](https://docs.drivequant.com/vehicle/references-ios#dkvehicleodometerhistory) models are described in the References part.

## Update odometer history

To update an entry to a vehicle’s odometer, call the following method:

```swift
func updateOdometerHistory(
    vehicleId: String,
    historyId: String,
    distance: Double,
    completionHandler: @escaping (DKOdometerUpdateHistoryStatus, DKVehicleOdometer?, [DKVehicleOdometerHistory]?) -> Void
)
```

This method have the following parameters:

| Name      | Type   | Description                                                     |
| --------- | ------ | --------------------------------------------------------------- |
| vehicleId | String | The vehicle id for which you want to update the odometer’s data |
| historyId | String | The history id for which you want to update the distance.       |
| distance  | Double | The distance in km you want to update                           |

[DKOdometerUpdateHistoryStatus](https://docs.drivequant.com/vehicle/references-ios#dkodometerupdatehistorystatus), [DKVehicleOdometer](https://docs.drivequant.com/vehicle/references-ios#dkvehicleodometer) and [DKVehicleOdometerHistory](https://docs.drivequant.com/vehicle/references-ios#dkvehicleodometerhistory) models are described in the References part.

## Delete odometer history

To delete vehicle’s odometer entry, call the following method:

```swift
func deleteOdometerHistory(
    vehicleId: String,
    historyId: String,
    completionHandler: @escaping (DKOdometerDeleteHistoryStatus, DKVehicleOdometer?, [DKVehicleOdometerHistory]?) -> Void
)
```

This method have the following parameters:

| Name      | Type   | Description                                                              |
| --------- | ------ | ------------------------------------------------------------------------ |
| vehicleId | String | The vehicle id for which you want to delete the odometer’s history entry |
| historyId | String | The history id you want to delete                                        |

[DKOdometerDeleteHistoryStatus](https://docs.drivequant.com/vehicle/references-ios#dkodometerdeletehistorystatus), [DKVehicleOdometer](https://docs.drivequant.com/vehicle/references-ios#dkvehicleodometer) and [DKVehicleOdometerHistory](https://docs.drivequant.com/vehicle/references-ios#dkvehicleodometerhistory) models are described in the References part.
