Basic Place Autocomplete component
The Basic Place Autocomplete component of the Places UI Kit lets you add an individual UI component that returns a place ID when a user selects a place. The component is a full screen cover that provides a search bar for users to enter a query. As the user types, a list of autocomplete results will be shown below the search bar. When the user taps on a place, a place object with only place ID is returned to the developer. This component is customizable.
The Basic Place Autocomplete component has the following customization options: list density, and whether to include location icons. Use AutocompleteUICustomization
to customize the component.
You can use the Basic Place Autocomplete component independently or in conjunction with other Google Maps Platform APIs and services.
Billing
You are billed each time the component is opened and a query is made. You won't be billed again for that session unless the session expires or a place is selected from the list.
Add the Basic Autocomplete component to your app
Set the autocomplete filter parameters (for example, the types to return, the country to limit results to, the region coordinates for results, the origin of the request to display distance information, if available) as you would to use Place Autocomplete (New) without the Places UI Kit. See the Place Autocomplete (New) documentation for full instructions and an example of the code to create an autocomplete filter.
Once you've created your autocomplete filter, add your UI customizations. See customization options and instructions.
Kotlin
AutocompleteUiCustomization.create( listDensity = AutocompleteListDensity.MULTI_LINE, listItemIcon = AutocompleteUiIcon.noIcon(), )
Java
AutocompleteUiCustomization.builder() .listItemIcon(AutocompleteUiIcon.noIcon()) .listDensity(AutocompleteListDensity.MULTI_LINE) .build()
Customize the Basic Autocomplete component
List density
You can choose to either display a two-line list or a multiline list. Use the options in AutocompleteListDensity
(TWO_LINE
or MULTI_LINE
) in the AutocompleteUICustomization
class. If you don't specify the list density, the component will display a two-line list.
Location icon
You can choose whether to display a default place icon on the results list. Use the options in AutocompleteUIIcon
(listItemDefaultIcon
or noIcon
) in the AutocompleteUICustomization
class.
Add customizations to the Basic Autocomplete component
Use the AutocompleteUICustomization
class to customize the Basic Autocomplete component.
Kotlin
.setAutocompleteUiCustomization( AutocompleteUiCustomization.create( listDensity = AutocompleteListDensity.MULTI_LINE, listItemIcon = AutocompleteUiIcon.noIcon(), ) )
Java
.setAutocompleteUiCustomization( AutocompleteUiCustomization.builder() .listItemIcon(AutocompleteUiIcon.noIcon()) .listDensity(AutocompleteListDensity.MULTI_LINE) .build() )
Example
This example creates a custom Basic Autocomplete component.
Kotlin
val basicPlaceAutocompleteActivityResultLauncher: ActivityResultLauncher<Intent> = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult -> val intent = result.data val place: Place? = BasicPlaceAutocomplete.getPlaceFromIntent(intent!!) val status: Status? = BasicPlaceAutocomplete.getResultStatusFromIntent(intent!!) // ... } val autocompleteIntent: Intent = BasicPlaceAutocomplete.createIntent(this) { setInitialQuery("INSERT_QUERY_TEXT") setOrigin(LatLng(10.0, 10.0)) // ... setAutocompleteUiCustomization( AutocompleteUiCustomization.create( listDensity = AutocompleteListDensity.MULTI_LINE, listItemIcon = AutocompleteUiIcon.noIcon(), ) ) } basicPlaceAutocompleteActivityResultLauncher.launch(autocompleteIntent)
Java
ActivityResultLauncher<Intent> basicPlaceAutocompleteActivityResultLauncher = registerForActivityResult( new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() { @Override public void onActivityResult(ActivityResult result) { Intent intent = result.getData(); if (intent != null) { Place place = BasicPlaceAutocomplete.getPlaceFromIntent(intent); Status status = BasicPlaceAutocomplete.getResultStatusFromIntent(intent); //... } } } ); Intent basicPlaceAutocompleteIntent = new BasicPlaceAutocomplete.IntentBuilder() .setInitialQuery("INSERT_QUERY_TEXT") .setOrigin(new LatLng(10.0, 10.0)) //... .setAutocompleteUiCustomization( AutocompleteUiCustomization.builder() .listItemIcon(AutocompleteUiIcon.noIcon()) .listDensity(AutocompleteListDensity.MULTI_LINE) .build()) .build(this); basicPlaceAutocompleteActivityResultLauncher.launch(basicPlaceAutocompleteIntent);