In order to execute the request that contains the query, we need a client.
We need a places client for the places API.
So for that, let me scroll up.
Before the Oncreate function.
You can initialize the places client.
So private late initiate.
VAR places api client which is of type places client.
Alt+.
Enter to import the class and in Oncreate function use places client equals to places dot.
Create client and pass this.
Also you can initialize in other activities, but I prefer in the main activity where your places API
is being called.
Okay then scroll down the places dot create client function.
Creates a singleton places client instance tied to the app's lifecycle, and this refers to the current
activity or context should be called once.
Typically in Oncreate function uses the Google Play Services SDK.
Under the hood.
Okay, this is how the places client being created now lets you.
Let's use this places client.
And here inside this if close places client dot find autocomplete predictions and pass the request that
you want dot add on success listener.
It's similar to Firebase.
So response go and set the predictions.
Set the response dot autocomplete predictions.
Otherwise add on failure listener error.
Getting predictions.
Here we are calling the client places a client and find autocomplete predictions, executing this function
and passing the request as the request for this predictions.
Autocomplete function.
So this code fetches autocomplete place predictions, search suggestions from Google places API and
updates the predictions list when And successful.
What does this code do?
Fetches place suggestions, updates predictions and run asynchronously.
Want to block the UI thread?
The places client that initialized.
Places client from places that create client and request containing the search query, for example New
York or Paris, and optional filters like country location bias and etc..
Add Onsuccess listener a callback triggered when the API request succeeded.
The response contains autocomplete predictions, list of autocomplete predictions, object and other
metadata like status and others, and predictions response.
Autocomplete predictions update the predictions state variable which is created up in the previous video,
and this triggers a UI recomposition if observed by composable.
Okay, this is the idea and the logic behind using the predictions and the places API.
Okay.
Now let's continue with the label.
So here on value change it's closed.
Set the label to text search places.
And also you can set the modifier to fill maximum width okay.
This is our colon.
And inside this colon.
And this is the text field.
We finished the text field.
Now you can create another composable which is lazy colon.
And this lazy colon contains the items of predictions.
So we need to display all predictions in a list in a custom list.
And for every prediction we need to create a text predictions dot get full text, for example.
Or you can customize, uh, some cards for this composable for every item in the predictions list.
Okay, in the next video, we're going to create our custom layout for every item in the predictions
list.