Woosmap MultiSearch iOS SDK
Basics and first steps to set the MultiSearch on iOS.
Installation
You can install the SDK in three different ways.
We recommend installing the SDK via Swift Package Manager.
Swift Package Manager
To integrate Woosmap Geofencing SDK into your project using Swift Package Manager, you can add the library as a dependency in Xcode (11 and above) – see adding package dependencies to your app on Apple documentation. The package repository URL is:
https://github.com/Woosmap/multisearch-ios
CocoaPods
Install CocoaPods, a dependency manager for Cocoa projects. If you don’t have an existing
Podfile, run pod init in your project directory. Add the following to your Podfile:
For usage and installation instructions, visit their website. To integrate Woosmap Geofencing SDK into your Xcode
project using CocoaPods, specify it in your Podfile
:
pod 'Multisearch', :git => 'https://github.com/Woosmap/multisearch-ios'
Importing the Framework manually
- Unzip MultiSearch-<version>.zip.
- Import the MultiSearch.framework folder into your Xcode project.
If Xcode has not automatically added the correct path(s), add a project-relative path to your framework.
Implementing the MultiSearch
Object
The library requires to set a key
for each available API in your MultiSearch implementation, whether it’s a Woosmap
API or for Google Places API.
Please refer to the documentation to get an API Key if necessary.
Additionally, for each provider configuration you can apply the same optional parameters as defined in the corresponding provider documentation.
When instantiating the Multisearch
object, specify your desired autocomplete services’ API
keys and the order in which these services will be called:
let localitiesProvider = ProviderConfig(searchType: .localities,
key: <<woosmap_private_key>>)
let addressProvider = ProviderConfig(searchType: .address,
key: <<woosmap_private_key>>)
let storeProvider = ProviderConfig(searchType: .store,
key: <<woosmap_private_key>>)
let placesProvider = ProviderConfig(searchType: .places,
key: <<google_api_web_key>>)
Then, create MultiSearch
object and add the providers to it using MultiSearch.addProvider()
method.
import Multisearch
private let objSearch = MultiSearch.init(debounceTime: 100)
// Order for calling multisearch api
objSearch.addProvider(config: localitiesProvider)
objSearch.addProvider(config: storeProvider)
objSearch.addProvider(config: addressProvider)
objSearch.addProvider(config: placesProvider)
APIs will be called based on the order in which they were provided to MultiSearch
object. In above code snippet
following will be the order of the APIs:
LOCALITIES
→ STORE
→ ADDRESS
→ PLACES
Specify debounceTime
Debounce time is the amount of time in milliseconds the autocomplete function will wait after the last received call before executing it. If 0 is specified then autocomplete function will not wait for the execution call.
Setting up callback
MultiSearch
routine returns the autocomplete and details results using block function. This block returns expected
results or a Woosmap error.
SearchCompletionHandler
: This callback will be invoked once MultiSearch finishes any of its autocomplete methods. This block has two parameters:- List of
AutocompleteResponseItem
objects. Value will be null if any exception has occurred. WoosmapException
exception object. Will be null if there was no exception during the execution.
- List of
DetailCompletionHandler
: This callback will be invoked once MultiSearch finishes any of its details methods. This block has two parameters:DetailsResponseItem
object. Value will be null if any exception has occurred.WoosmapException
exception object. Will be null if there was no exception during the execution.
Retrieve suggestions
You can retrieve suggestions from the user input by calling the autocompleteMulti
method:
objSearch.autocompleteMulti(input: "paris") { (results, error) in }
Get Details
Finally, to get the suggestion details when a user selects one from the pick list, call the details
method. This
method accepts two parameters:
id
: id of the item retrieved fromautocompleteXXXX
method.apiType
: Underlying API type which will be called to fetch the details. Accepts enum ofSearchProviderType
type.
objSearch.details(id: "UGFyaXMsIMOObGUtZGUtRnJhbmNlLCBGcmFuY2U=", provider: .store) { (locationinfo, error) in }