Quickstart

VERSION 0.54.0

The Routing SDK provides the tools to integrate the TomTom Routing API into an iOS application. It is used to calculate a route between an origin and a destination, using a range of options and taking traffic into account. Read more about TomTom’s Routing parameters.

Project setup

To use the Routing SDK, you will need to configure the project according to the project setup guide and import the necessary frameworks using the following instructions, based on your preferred package manager:

Swift Package Manager
  1. Open your App’s target and navigate to General > Frameworks, Libraries, and Embedded Content.
  2. Add the following TomTomSDK libraries from the provided code snippet. Once the project is set up, import the mentioned frameworks into your code.
import TomTomSDKRoutePlannerOnline
CocoaPods
  1. Add the TomTomSDKRoutePlanner and the TomTomSDKRoutePlannerOnline modules to your project’s Podfile:
    1TOMTOM_SDK_VERSION = '0.54.0'
    2
    3target 'YourAppTarget' do
    4 use_frameworks!
    5 pod 'TomTomSDKRoutePlanner', TOMTOM_SDK_VERSION
    6 pod 'TomTomSDKRoutePlannerOnline', TOMTOM_SDK_VERSION
    7end
  2. Install the dependencies by executing the following commands in the project directory:
    pod repo-art update tomtom-sdk-cocoapods
    pod install --repo-update
  3. Once the project is set up and both routing modules are added to your target, import the following frameworks:
    import TomTomSDKRoutePlannerOnline

Routing SDK entry point

After all the preparations above, you can initialize the OnlineRoutePlanner object. It is the entry point for performing routing requests.

1init() {
2 self.routePlanner = OnlineRoutePlanner(apiKey: "YOUR_TOMTOM_API_KEY")
3}

Storing API keys directly in the codebase, as currently done, poses significant security risks and vulnerabilities; we strongly recommend adopting a more secure method for API key storage.

Routing basic usage

The TomTomSDKRoutePlannerOnline module can be used to obtain a route between two points. This module must be used with the TomTomSDKRoutePlanner module.

To calculate a route from A to B, you need to provide route planning criteria. They are built using the RoutePlanningOptions struct. Once you have a RoutePlanningOptions instance, pass it to the OnlineRoutePlanner.planRoute(options:onRouteReady:completion:) method to get the result. Read more about routing options and route planning in the Planning a route guide.

For a more advanced navigation experience, you can add optional intermediate locations to the route. You can learn more about this feature in the Waypoints and custom routes guide.

There are two options for planning a route:

The faster method delivers only the first guidance increment. This guidance increment contains one or more potentially combinable instructions and the corresponding lane guidance.