WEBVTT

00:00.080 --> 00:05.520
In order to execute the request that contains the query, we need a client.

00:05.680 --> 00:09.720
We need a places client for the places API.

00:10.200 --> 00:12.800
So for that, let me scroll up.

00:12.920 --> 00:15.000
Before the Oncreate function.

00:15.000 --> 00:18.200
You can initialize the places client.

00:18.200 --> 00:21.600
So private late initiate.

00:21.640 --> 00:28.600
VAR places api client which is of type places client.

00:28.640 --> 00:29.280
Alt+.

00:29.280 --> 00:39.200
Enter to import the class and in Oncreate function use places client equals to places dot.

00:39.200 --> 00:42.760
Create client and pass this.

00:42.920 --> 00:51.320
Also you can initialize in other activities, but I prefer in the main activity where your places API

00:51.320 --> 00:52.360
is being called.

00:52.680 --> 00:58.400
Okay then scroll down the places dot create client function.

00:58.400 --> 01:06.200
Creates a singleton places client instance tied to the app's lifecycle, and this refers to the current

01:06.200 --> 01:09.640
activity or context should be called once.

01:09.640 --> 01:14.590
Typically in Oncreate function uses the Google Play Services SDK.

01:14.630 --> 01:15.590
Under the hood.

01:15.630 --> 01:21.430
Okay, this is how the places client being created now lets you.

01:21.470 --> 01:24.790
Let's use this places client.

01:24.790 --> 01:36.030
And here inside this if close places client dot find autocomplete predictions and pass the request that

01:36.030 --> 01:40.270
you want dot add on success listener.

01:40.270 --> 01:43.110
It's similar to Firebase.

01:43.430 --> 01:46.870
So response go and set the predictions.

01:47.110 --> 01:50.710
Set the response dot autocomplete predictions.

01:50.750 --> 01:53.950
Otherwise add on failure listener error.

01:53.990 --> 01:55.550
Getting predictions.

01:55.670 --> 02:05.270
Here we are calling the client places a client and find autocomplete predictions, executing this function

02:05.270 --> 02:10.950
and passing the request as the request for this predictions.

02:10.990 --> 02:12.470
Autocomplete function.

02:12.470 --> 02:21.710
So this code fetches autocomplete place predictions, search suggestions from Google places API and

02:21.750 --> 02:25.460
updates the predictions list when And successful.

02:25.500 --> 02:27.780
What does this code do?

02:27.820 --> 02:34.020
Fetches place suggestions, updates predictions and run asynchronously.

02:34.060 --> 02:36.620
Want to block the UI thread?

02:36.740 --> 02:39.820
The places client that initialized.

02:39.820 --> 02:48.860
Places client from places that create client and request containing the search query, for example New

02:48.900 --> 02:55.580
York or Paris, and optional filters like country location bias and etc..

02:55.620 --> 03:01.420
Add Onsuccess listener a callback triggered when the API request succeeded.

03:01.540 --> 03:08.700
The response contains autocomplete predictions, list of autocomplete predictions, object and other

03:08.700 --> 03:13.740
metadata like status and others, and predictions response.

03:14.020 --> 03:23.740
Autocomplete predictions update the predictions state variable which is created up in the previous video,

03:23.740 --> 03:29.580
and this triggers a UI recomposition if observed by composable.

03:29.620 --> 03:36.860
Okay, this is the idea and the logic behind using the predictions and the places API.

03:36.980 --> 03:37.540
Okay.

03:37.740 --> 03:41.100
Now let's continue with the label.

03:41.100 --> 03:44.660
So here on value change it's closed.

03:44.900 --> 03:48.580
Set the label to text search places.

03:48.820 --> 03:53.540
And also you can set the modifier to fill maximum width okay.

03:53.820 --> 03:55.940
This is our colon.

03:55.940 --> 03:57.460
And inside this colon.

03:57.460 --> 03:59.620
And this is the text field.

03:59.620 --> 04:01.620
We finished the text field.

04:01.820 --> 04:08.460
Now you can create another composable which is lazy colon.

04:08.460 --> 04:13.740
And this lazy colon contains the items of predictions.

04:13.740 --> 04:22.300
So we need to display all predictions in a list in a custom list.

04:22.300 --> 04:31.460
And for every prediction we need to create a text predictions dot get full text, for example.

04:31.500 --> 04:41.500
Or you can customize, uh, some cards for this composable for every item in the predictions list.

04:41.540 --> 04:49.620
Okay, in the next video, we're going to create our custom layout for every item in the predictions

04:49.900 --> 04:50.380
list.
