StructuredSearchSession
public protocol StructuredSearchSession
A session represents the current state of the structured search process. The search proceeds as a series of steps and intermediate searches until the client reaches the destination address.
- The session starts with the
StructuredSearchSession.fetchStructuredSearchState(completion:)call, which returns the initial state. - Then, the client can select a candidate in the current step with the ‘StructuredSearchSession.selectCandidate(candidate:completion:)
call. [Optional] 3. After proceeding with the search, the client can go back to the previous step with theStructuredSearchSession.goBack(step:completion:)` call.
Here is a flow to get to the house address using Structured Search:
- prefecture/metropolitan -> municipality -> oaza -> chome/aza -> (gaiku-)houseNumber(-sub)
For example:
“Japan” -> “Saitama Prefecture” -> “Saitama City Minami Ward” -> “Negishi” -> “5 chome” -> “2-13-3”
Note
for more information, seeStructuredSearchdocumentation.
-
Fetch the current structured search state. This can be used to retrieve the initial state with candidates representing the top level of address, such as country.
Note
to proceed with the search, use theStructuredSearchSession.selectCandidate(candidate:completion:)call.Declaration
Swift
func fetchStructuredSearchState(completion: @escaping (Result<StructuredSearchResponse, Error>) -> ())Parameters
completionThe completion closure is called after the response to the request has been processed. If no errors occurred,
StructuredSearchResponsecontains the latest structured search state. -
Select a specific candidate in the current step. This will advance to the next step of the search path.
Note
to go back to the previous step, use theStructuredSearchSession.goBack(step:completion:)call.Declaration
Swift
func selectCandidate( candidate: StructuredSearchCandidate, completion: @escaping (Result<StructuredSearchResponse, Error>) -> () )Parameters
candidateThe candidate to select in the current step.
completionThe completion closure is called after the response to the request has been processed. If no errors occurred,
StructuredSearchResponsecontains the latest structured search state. -
Go back to previous selection from current step.
stepmust be a positive value. Ifstepis larger than the number of steps that have been taken, e.g.goBackis called withstepset to 9 at the third step, it goes back to the first step.Declaration
Swift
func goBack(step: Int, completion: @escaping (Result<StructuredSearchResponse, Error>) -> ())Parameters
stepThe number of step to go back.
completionThe completion closure is called after the response to the request has been processed. If no errors occurred,
StructuredSearchResponsecontains the latest structured search state. -
Set locale for the search session. The locale is used to find the best representation of strings in
StructuredSearchCandidate.Declaration
Swift
func setLocale(locale: Locale, completion: @escaping (Result<StructuredSearchResponse, Error>) -> ())Parameters
localeThe preferred
Locale.completionThe completion closure is called after changing locale has been finished. If no errors occurred,
StructuredSearchResponsecontains the latest structured search state.
-
goBack(completion:Extension method) Go back to the previous selection from current step. If nothing was selected before, nothing will happen.
Declaration
Swift
public func goBack(completion: @escaping (Result<StructuredSearchResponse, Error>) -> ())Parameters
completionThe completion closure is called after the response to the request has been processed. If no errors occurred,
StructuredSearchResponsecontains the latest structured search state.
TomTom SDK for iOS (0.53.1)
StructuredSearchSession