🔍Autocomplete Overview
Autocomplete is used to provide real-time suggestions for locations as the user types in a query.
Compass currently provides an interface for interacting with a geocoding service, such as Mapbox. The autocomplete feature provides real-time suggestions to the user as they type an address or location into a search field.
The library is structured around several key components:
AutocompleteService: This is an interface that represents a service providing autocomplete suggestions. It has asearch(query: String)function, which searches for autocomplete suggestions based on the provided query.AutocompleteResult: This is a sealed class that represents the result of an autocomplete operation. It can either be aSuccesswith a list of data or anErrorwith a specific error message.Autocomplete: This is a function that creates a new instance ofAutocompleteServicethat uses a HTTP service to provide autocomplete suggestions.
Quick start
suspend fun autocomplete(query: String): List<Place> {
val autocomplete = AutoComplete.mobile()
return autocomplete.search("London").getOrNull()
}In this quick example the AutoComplete.mobile()() function is a convenience function for creating a AutoComplete<Place> object. Each of the autocomplete-* artifacts provide one.
Last updated
Was this helpful?