WEBVTT

00:00.080 --> 00:03.120
We created that prediction item composable.

00:03.160 --> 00:05.240
Now let's move back to the main activity.

00:05.240 --> 00:13.440
And inside this lazy colon of the colon that it is responsible for the places API overlay, we need

00:13.440 --> 00:15.880
to pass the two parameters.

00:15.920 --> 00:23.400
The prediction equals to prediction, which is the parameter of the lambda expression of the for each

00:23.440 --> 00:24.080
item.

00:24.400 --> 00:27.720
And here pass that on.

00:27.760 --> 00:30.040
Click on item click.

00:30.080 --> 00:34.040
This is the lambda expression that we need to work with.

00:34.040 --> 00:37.080
I want from you to focus with me here.

00:37.280 --> 00:45.800
When the user clicks on any item in any prediction, we need to fetch place details when clicked.

00:46.000 --> 00:53.240
Also, we know we need to pass the request to the client and get the data from the client.

00:53.240 --> 01:03.790
So first step is for each place details when clicked when prediction text when place is clicked.

01:03.830 --> 01:09.390
Val place fields for example, equals to list of.

01:09.750 --> 01:15.790
Let me get some ids name, lat, long and address.

01:15.790 --> 01:19.390
These are the place data.

01:19.390 --> 01:30.350
For example place field id place dot field, dot name, display name, resource name rating, good for

01:30.350 --> 01:30.990
children.

01:30.990 --> 01:33.150
Location, primary type display.

01:33.190 --> 01:39.630
You see guys there is a big collection of things you can get.

01:39.630 --> 01:42.710
There are many attributes.

01:42.710 --> 01:45.150
You can get many data.

01:45.190 --> 01:48.150
You can get fuel option.

01:48.150 --> 01:51.990
Good for children, good for groups watching sports.

01:52.350 --> 01:56.550
I can mask URL, live music location and so on.

01:56.550 --> 02:05.220
There are a lot of things you can fetch we are interested in name for example display name lat long

02:05.500 --> 02:10.900
of course and place dot field dot address.

02:11.020 --> 02:15.260
Then the second step is to create the request.

02:16.220 --> 02:24.260
Request equals to fetch place request dot new instance.

02:24.580 --> 02:30.580
Pass the prediction place ID and pass the place fields.

02:30.580 --> 02:38.620
Here we are fetching detailed information about selected place like coordinates, address, photos or

02:38.660 --> 02:44.820
etc. using the Google Places API and updates the map camera position.

02:44.820 --> 02:52.620
Then we need to create the third step which is fetching place places client.

02:52.660 --> 03:01.600
Here we need to use the client dot place to send the request as a parameter.

03:01.760 --> 03:04.760
Dot add Onsuccess listener.

03:04.840 --> 03:09.400
The response as a parameter for this lambda expression.

03:09.600 --> 03:14.600
Selected place equals to response dot place.

03:14.800 --> 03:16.240
Getting from the place.

03:16.480 --> 03:19.880
And now we need to move the camera.

03:19.920 --> 03:23.000
Move the camera to selected place.

03:23.040 --> 03:25.440
Response dot place.

03:25.480 --> 03:27.000
Dot Latlong.

03:27.160 --> 03:36.520
If it is not null, then move and create this lambda expression camera position state dot position equals

03:36.520 --> 03:47.280
to camera position dot from latlong zoom to Latlong okay and set to 15 F as the zoom level.

03:47.320 --> 03:51.600
Here the fetch place request dot new instance.

03:51.640 --> 03:58.910
The place ID is a unique identifier for the place from autocomplete prediction dot place id and please

03:58.910 --> 04:04.070
fields a list of place fields specifying the data to fetch.

04:04.070 --> 04:09.350
And in this example we need to fetch the id displayname lat long and address.

04:09.390 --> 04:16.550
Places client dot fetch place sends the request to the Google Places API.

04:16.590 --> 04:18.950
So let me write this node down.

04:18.990 --> 04:20.470
Please pay attention.

04:20.470 --> 04:28.710
Returns a task of fetch place response asynchronous task and add on synchronous add Onsuccess listener

04:28.710 --> 04:31.670
triggered when the API call succeeded.

04:31.710 --> 04:41.030
Response dot place contains the fetched place object with all requested fields, and the selected place

04:41.070 --> 04:51.350
typically is a mutable state that we created before and if we are using Viewmodels in in Xaml and in

04:51.350 --> 04:54.270
Android views, it's a live data.

04:54.270 --> 05:00.700
The camera position state controls the maps view zooms to the selected location.

05:00.700 --> 05:06.980
Let me run our application and see the places API in action.

05:07.020 --> 05:07.340
Oops.

05:07.340 --> 05:10.580
We have this error for linking reference.

05:10.660 --> 05:15.500
Scroll up style attribute and it's not found.

05:15.500 --> 05:23.740
The corner family corner size are from the material theme dependency so build.gradle file.

05:23.980 --> 05:32.460
Open it, then paste this dependency for material theme in order to solve this error.

05:32.700 --> 05:33.300
Sync.

05:33.300 --> 05:37.020
Now build the project and clean the project.

05:37.020 --> 05:41.900
Run the application and let's let's see the places API.

05:42.020 --> 05:42.820
Here we go.

05:42.860 --> 05:45.980
This is our application search places.

05:46.260 --> 05:49.860
Let me search for example times.

05:49.860 --> 05:50.940
Here we have an error.

05:50.940 --> 05:59.680
If I type anything, nothing changed except that there are there are Letters that appear in this search

05:59.680 --> 06:00.120
bar.

06:00.240 --> 06:05.360
So I think the the on value change is the problem here.

06:05.400 --> 06:06.320
The search query.

06:06.360 --> 06:11.680
You see guys, I am um I'm getting the wrong one.

06:11.880 --> 06:15.560
So set the places query equals to the new query.

06:15.840 --> 06:17.960
Run again our application.

06:17.960 --> 06:23.280
Let's search places for example Times Square.

06:23.520 --> 06:27.920
You see guys the suggestions we have five suggestions.

06:28.000 --> 06:30.200
Uh, this is in Dubai.

06:30.240 --> 06:31.880
This is in Hong Kong.

06:31.920 --> 06:37.160
This is in New York, in New York City, in USA, in Manhattan.

06:37.160 --> 06:38.920
Let me click on it.

06:38.920 --> 06:49.240
And you can see guys that we have this very, very good example about getting the places.

06:49.240 --> 06:55.560
And there is a new marker called here and Times Square, Manhattan, New York City.

06:55.760 --> 07:05.270
We get information also, uh, we we, uh, we get a lot of things using this search places.

07:05.270 --> 07:08.190
So this is the power of using places API.

07:08.430 --> 07:11.070
Let me search another place.

07:11.070 --> 07:13.590
And by the way, we are using this map overlay.

07:13.590 --> 07:17.270
So don't be, uh, confused.

07:17.310 --> 07:22.310
This is the map overlay from the previous videos over New York.

07:22.510 --> 07:23.310
Let me.

07:23.430 --> 07:30.790
Burj Khalifa, Burj Khalifa, this is the Burj Khalifa marker.

07:31.070 --> 07:32.350
It's in Dubai.

07:32.590 --> 07:34.630
And here we go.

07:34.830 --> 07:36.830
So congratulations, guys.

07:36.830 --> 07:44.030
This is our lovely application with this suggestions and search places.

07:44.190 --> 07:47.070
It's a very, very important.

07:47.270 --> 07:51.990
This is a very, very exciting and very complex application.

07:51.990 --> 07:57.310
By the way, many developers had errors in this API.
