Quickstart

VERSION 0.67.0

The Search module provides easy-to-use APIs to add search functionality to your application. It is built on top of TomTom Search APIs and has offline support.

We also have an off-the-shelf UI component named TomTomSDKSearchUI.

Offline functionality is only available upon request. Contact us to get started.

Project setup

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.
1import TomTomSDKCommon
2import TomTomSDKNavigationEngines
3import TomTomSDKRoute
4import TomTomSDKSearch
5import TomTomSDKSearchOnline
CocoaPods
  1. Add the TomTomSDKSearchOnline module dependency to your project’s Podfile:
    1TOMTOM_SDK_VERSION = '0.67.0'
    2
    3target 'YourAppTarget' do
    4 use_frameworks!
    5 pod 'TomTomSDKSearchOnline', TOMTOM_SDK_VERSION
    6 pod 'TomTomSDKSearchUI', 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. Import the following frameworks:
    1import TomTomSDKCommon
    2import TomTomSDKNavigationEngines
    3import TomTomSDKRoute
    4import TomTomSDKSearch
    5import TomTomSDKSearchOnline

Using Search module APIs

The Search module is composed of several frameworks. The TomTomSDKSearch framework provides the common API protocols and types. The TomTomSDKSearchOnline framework provides an online implementation of the Search protocol.

If you want to bring your own POI data for search, check the Bring your own data guide.

Making search API calls

The online implementation of Search is highly configurable and supports various kinds of searches, for example, searching certain POIs by category, searching inside certain geometries, and searching along a route. It also provides auxiliary APIs such as autocompletion for brands and categories, listing POI categories, and getting POI details.

To start using the API, create a Search instance using OnlineSearchFactory:

let onlineSearch = OnlineSearchFactory.create(apiKey: "YOUR_TOMTOM_API_KEY")

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.

With the Search instance, a search request with geobias can be done like:

1let options = SearchOptions(
2 query: "TomTom",
3 geoBias: CLLocationCoordinate2D(latitude: 52.377956, longitude: 4.897070),
4 limit: 5
5)
6onlineSearch.search(options: options) { result in
7 switch result {
8 case let .success(fuzzySearchResponse):
9 // handle success
10 break
11 case let .failure(error):
12 // handle error
13 break
14 }
15}