AutocompleteOptions
public struct AutocompleteOptions
Defines the parameters of the Autocomplete Search.
Use AutocompleteOptions
to make an Autocomplete Search request.
To learn more about Autocomplete refer to the autocomplete(options:completion:)
description.
You can also provide optional parameters to perform a more accurate search, following similar recommendation
as for search(options:completion:)
.
An example of autocomplete searching for a restaurant in Amsterdam:
let amsterdam = CLLocationCoordinate2D(latitude: 52.369979,
longitude: 4.891820)
let options = AutocompleteOptions(
query: "Rest",
position: amsterdam,
radius: Measurement(value: 3, unit: .kilometers),
countries: ["NL"],
resultTypes: [.brand, .category],
sessionID: UUID().uuidString
)
-
Creates an instance of
AutocompleteOptions
, that is used inautocomplete(options:completion:)
to specify a list of suggestions.Declaration
Swift
public init( query: String, locale: Locale = Locale.current, limit: Int = Defaults.limit, position: CLLocationCoordinate2D? = nil, radius: Measurement<UnitLength>? = nil, countries: Set<String> = [], resultTypes: Set<AutocompleteResultType> = [], sessionID: UUID? = nil )
Parameters
query
A search phrase to find an autocomplete text for, e.g., “Res” to autocomplete with “Restaurant”.
locale
The locale that specifies the language in which autocomplete results should be returned. Locale should be created with one of the TomTom supported Internet Engineering Task Force (IETF) language tags: https://developer.tomtom.com/search-api/documentation/product-information/supported-languages
limit
Limits the number of autocomplete suggestions.
position
radius
A radius that defines an area around
position
.countries
A list of country codes in the ISO 3166-1 alpha-2 format, e.g.,
["FR", "BR"]
. When used the results will be limited to the specified countries.resultTypes
Defines the types of results to return, e.g.,
[.brand, .category]
.sessionID
A search session during which a user performs multiple search requests. This is needed for sending the feedback to the online search engine.
-
Defines default parameters for
See moreAutocompleteOptions
Declaration
Swift
public enum Defaults
-
The search query used to generate autocomplete suggestions for text input.
For instance, setting the query as “Res” could result in an autocomplete suggestion of “Restaurant”. An error will be returned if the
query
is empty.Declaration
Swift
public let query: String
-
Locale in which autocomplete results should be returned. Locale should be created with one of the TomTom supported IETF language tags: https://developer.tomtom.com/search-api/documentation/product-information/supported-languages e.g.,
Locale(identifier: "en-GB")
If locale is not defined, Autocomplete Search uses the systemLocale
. If locale is not supported, an error is returned on the attempt to useAutocompleteOptions
for searching.Declaration
Swift
public let locale: Locale
-
Limits the number of autocomplete suggestions. If
nil
is set, a default value is used fromlimit
The maximum value is 10. The limit of more than the maximum triggers an error.Declaration
Swift
public var limit: Int?
-
A geographical location to enhance the relevance of autocomplete suggestions.
Enhances nearby results when
position
is used with an emptyradius
. Limits results to a specific area when used withradius
. Ifposition
is not set, other options are used for prioritizing results.Declaration
Swift
public var position: CLLocationCoordinate2D?
-
A radius that defines a circle area around
position
to limit autocomplete results. The radius parameter must be used in conjunction withposition
. Allowed values are within 0…5000 km. Values greater than 5,000 km are reduced to 5,000 km. Values less than 0 will return an error. Ifradius
is not set, autocomplete results will be biased only to the providedposition
.Declaration
Swift
public var radius: Measurement<UnitLength>?
-
A set of country codes in the ISO 3166-1 alpha-2 format limiting the autocomplete results (e.g.,
["FR", "BR"]
). For more information, see: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 When used the results will be limited to the specified countries.Declaration
Swift
public var countries: Set<String>
-
Defines the types of results to return. Restricts the search results based on their types. A result is only included if it contains a
segment
of any of the indicated types. For example:[.category, .brand]
If parameterresultTypes
is not set, it allowed results with any segment:brand
,category
,plain text
.Declaration
Swift
public var resultTypes: Set<AutocompleteResultType>
-
The unique session identifier, that defines a period during which a user interacts with the TomTom Search SDK.
It can be limited by the time when a user performs the first request until the moment when a user leaves the Search screen or closes the app. When a user starts typing, a session ID should be generated ( e.g., by
let uuid = UUID()
) and used until the user selects a result, which marks the end of a session. This is needed for sending the feedback about search engine performance. It helps improve search results. Use it in theFeedbackEvent
when callingsendFeedback(feedbackEvent:completion:)
.Declaration
Swift
public let sessionID: UUID?