Quickstart

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.
import TomTomSDKCommon
import TomTomSDKNavigationEngines
import TomTomSDKRoute
import TomTomSDKSearch
import TomTomSDKSearchOnline
CocoaPods
  1. Add the TomTomSDKSearchOnline module dependency to your project’s Podfile:
    TOMTOM_SDK_VERSION = '0.71.1'
    target 'YourAppTarget' do
    use_frameworks!
    pod 'TomTomSDKSearchOnline', TOMTOM_SDK_VERSION
    pod 'TomTomSDKSearchUI', TOMTOM_SDK_VERSION
    end
  2. Install the dependencies by executing the following commands in the project directory:
    pod repo update tomtom-sdk-cocoapods
    pod install --repo-update
  3. Import the following frameworks:
    import TomTomSDKCommon
    import TomTomSDKNavigationEngines
    import TomTomSDKRoute
    import TomTomSDKSearch
    import 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:

let options = SearchOptions(
query: "TomTom",
geoBias: CLLocationCoordinate2D(latitude: 52.377956, longitude: 4.897070),
limit: 5
)
onlineSearch.search(options: options) { result in
switch result {
case let .success(fuzzySearchResponse):
// handle success
break
case let .failure(error):
// handle error
break
}
}