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
- Open your App’s target and navigate to General > Frameworks, Libraries, and Embedded Content.
- Add the following TomTomSDK libraries from the provided code snippet. Once the project is set up, import the mentioned frameworks into your code.
1import TomTomSDKCommon2import TomTomSDKNavigationEngines3import TomTomSDKRoute4import TomTomSDKSearch5import TomTomSDKSearchOnline
CocoaPods
- Add the
TomTomSDKSearchOnline
module dependency to your project’sPodfile
:1TOMTOM_SDK_VERSION = '0.65.0'23target 'YourAppTarget' do4 use_frameworks!5 pod 'TomTomSDKSearchOnline', TOMTOM_SDK_VERSION6 pod 'TomTomSDKSearchUI', TOMTOM_SDK_VERSION7end - Install the dependencies by executing the following commands in the project directory:
pod repo-art update tomtom-sdk-cocoapodspod install --repo-update
- Import the following frameworks:
1import TomTomSDKCommon2import TomTomSDKNavigationEngines3import TomTomSDKRoute4import TomTomSDKSearch5import 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: 55)6onlineSearch.search(options: options) { result in7 switch result {8 case let .success(fuzzySearchResponse):9 // handle success10 break11 case let .failure(error):12 // handle error13 break14 }15}