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 in autocomplete(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

    When position is used on its own, results nearer the location will be boosted. When used in combination with radius, results will be constrained to the defined area.

    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 AutocompleteOptions

    See more

    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 system Locale. If locale is not supported, an error is returned on the attempt to use AutocompleteOptions for searching.

    Declaration

    Swift

    public let locale: Locale
  • Limits the number of autocomplete suggestions. If nil is set, a default value is used from limit 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 empty radius. Limits results to a specific area when used with radius. If position 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 with position. 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. If radius is not set, autocomplete results will be biased only to the provided position.

    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 the FeedbackEvent when calling sendFeedback(feedbackEvent:completion:).

    Declaration

    Swift

    public let sessionID: UUID?