Dynamic data
The Dynamic Data module is comprised of four APIs: fuel prices, parking availability, parking prices and EV charging availability. These APIs provide up-to-date information and can be useful for drivers to decide where to park, refill and charge.
Initializing
To use our dynamic data feed, you must configure its credentials and add the SDK as a dependency:
- Get your TomTom API Key and configure the project as described in the Project setup guide .
- Add the
Dynamic datamodule dependency in thebuild.gradle.ktsof your application module and synchronize the project.implementation("com.tomtom.sdk.search:dynamic-data-online:1.26.4")
Fuel prices
The fuel prices API provides information on the current fuel prices at a specified fuel station. The only required request parameter is the fuel station identifier, which can be fetched from Fuzzy Search . The identifier is in the SearchResultId of the SearchResult , labeled fuelPriceId .
val fuelPriceOptions = searchResult.searchResultId.fuelPriceId?.let { fuelPriceId -> FuelPriceOptions(fuelPriceId) }A successful request returns a FuelPriceResponse . If the request fails, a SearchFailure is returned.
fuelPriceProvider = OnlineDynamicDataProviderFactory.createFuelPriceProvider(context, "YOUR_TOMTOM_API_KEY")fuelPriceOptions?.let { options -> fuelPriceProvider.requestFuelPrices( options, object : FuelPriceCallback { override fun onSuccess(result: FuelPriceResponse) { // YOUR CODE GOES HERE }
override fun onFailure(failure: SearchFailure) { // YOUR CODE GOES HERE } }, )}Parking availability
The parking availability API provides up-to-date information about the number of available parking places and the trend in occupancy at a specified parking location. The only required parameter is the parking information identifier.
You can get this identifier from the result of a Fuzzy Search . The identifier is in the SearchResultId of the SearchResult , labeled parkingDetailId .
val parkingAvailabilityOptions = searchResult.searchResultId.parkingDetailId?.let { parkingDetailId -> ParkingAvailabilityOptions(parkingDetailId) }A successful request returns ParkingAvailabilityResponse . If the request fails, a SearchFailure is returned.
parkingDetailProvider = OnlineDynamicDataProviderFactory.createParkingDetailProvider( context, "YOUR_TOMTOM_API_KEY", )parkingAvailabilityOptions?.let { options -> parkingDetailProvider.requestParkingAvailability( options, object : ParkingAvailabilityCallback { override fun onSuccess(result: ParkingAvailabilityResponse) { // YOUR CODE GOES HERE }
override fun onFailure(failure: SearchFailure) { // YOUR CODE GOES HERE } }, )}Parking prices
The parking prices API provides up-to-date parking price information of the specified parking location. The only required parameter is the parking information identifier.
You can get this identifier by doing a Fuzzy Search . The identifier is in the SearchResultId of the SearchResult , labeled parkingDetailId .
val parkingPriceOptions = searchResult.searchResultId.parkingDetailId?.let { parkingDetailId -> ParkingPriceOptions( parkingDetailId = parkingDetailId, startTime = Calendar.getInstance(), duration = 3.hours, ) }A successful request returns a ParkingPriceResponse . If the request fails, a SearchFailure is returned.
parkingDetailProvider = OnlineDynamicDataProviderFactory.createParkingDetailProvider( context, "YOUR_TOMTOM_API_KEY", )parkingPriceOptions?.let { options -> parkingDetailProvider.requestParkingPrice( options, object : ParkingPriceCallback { override fun onSuccess(result: ParkingPriceResponse) { // YOUR CODE GOES HERE }
override fun onFailure(failure: SearchFailure) { // YOUR CODE GOES HERE } }, )}EV charging availability
The EV charging availability API provides information on the availability of Electric Vehicle (EV) charging points at a specific charging park. The only required parameter is the charging availability identifier, which can be fetched from Fuzzy Search . The identifier is in the SearchResultId of the evChargingAvailabilityId .
val evChargingAvailabilityOptions = searchResult.searchResultId.evChargingAvailabilityId?.let { chargingAvailabilityId -> EvChargingAvailabilityOptions( availabilityId = chargingAvailabilityId, connectors = setOf( ConnectorType.Iec62196Type1Ccs, ConnectorType.Iec62196Type3, ), minPower = Power.kilowatts(5), maxPower = Power.kilowatts(15), ) }A successful request returns an EvChargingAvailabilityResponse . If the request fails, a SearchFailure is returned.
evChargingAvailabilityProvider = OnlineDynamicDataProviderFactory.createEvChargingAvailabilityProvider(context, "YOUR_TOMTOM_API_KEY")
evChargingAvailabilityOptions?.let { options -> evChargingAvailabilityProvider.requestEvChargingAvailability( options, object : EvChargingAvailabilityCallback { override fun onSuccess(result: EvChargingAvailabilityResponse) { // YOUR CODE GOES HERE }
override fun onFailure(failure: SearchFailure) { // YOUR CODE GOES HERE } }, )}