Free Text Search
In this guide you will learn how to do a text search and display them in a list.
Search service
Inside MainActivity.kt
retain a SearchService
instance.
Normally in Android's MVVM, services are retained in the Repository layer, injected via dependency injection, and ultimately consumed by ViewModels but for the scope of this example we will use it inside an activity.
The search service has a onCompleted
callback which will update the UI.
Searching by filter
Initiate a new search each time the query gets updated. If there is a pre-existing search process it will be canceled. The reference point will be taken into account when calculating the relative distance of query-matching locations found during the search process. As a result, the relevance of these locations will change, and the order in which the results appear may vary depending on the reference point.
Refreshing the list
After each call to searchService.searchByFilter(filter, reference)
onCompleted
callback will be invoked by the SDK. If there have been no errors the received LandmarkList
is mapped to SearchItem
data class which holds and displays only key information. The resulted list is held in a lifecycle-aware component (LiveData
) which updates the UI each time a new result list gets submitted.
Finally, a ListAdapter was used for displaying the list.