We created that prediction item composable.
Now let's move back to the main activity.
And inside this lazy colon of the colon that it is responsible for the places API overlay, we need
to pass the two parameters.
The prediction equals to prediction, which is the parameter of the lambda expression of the for each
item.
And here pass that on.
Click on item click.
This is the lambda expression that we need to work with.
I want from you to focus with me here.
When the user clicks on any item in any prediction, we need to fetch place details when clicked.
Also, we know we need to pass the request to the client and get the data from the client.
So first step is for each place details when clicked when prediction text when place is clicked.
Val place fields for example, equals to list of.
Let me get some ids name, lat, long and address.
These are the place data.
For example place field id place dot field, dot name, display name, resource name rating, good for
children.
Location, primary type display.
You see guys there is a big collection of things you can get.
There are many attributes.
You can get many data.
You can get fuel option.
Good for children, good for groups watching sports.
I can mask URL, live music location and so on.
There are a lot of things you can fetch we are interested in name for example display name lat long
of course and place dot field dot address.
Then the second step is to create the request.
Request equals to fetch place request dot new instance.
Pass the prediction place ID and pass the place fields.
Here we are fetching detailed information about selected place like coordinates, address, photos or
etc. using the Google Places API and updates the map camera position.
Then we need to create the third step which is fetching place places client.
Here we need to use the client dot place to send the request as a parameter.
Dot add Onsuccess listener.
The response as a parameter for this lambda expression.
Selected place equals to response dot place.
Getting from the place.
And now we need to move the camera.
Move the camera to selected place.
Response dot place.
Dot Latlong.
If it is not null, then move and create this lambda expression camera position state dot position equals
to camera position dot from latlong zoom to Latlong okay and set to 15 F as the zoom level.
Here the fetch place request dot new instance.
The place ID is a unique identifier for the place from autocomplete prediction dot place id and please
fields a list of place fields specifying the data to fetch.
And in this example we need to fetch the id displayname lat long and address.
Places client dot fetch place sends the request to the Google Places API.
So let me write this node down.
Please pay attention.
Returns a task of fetch place response asynchronous task and add on synchronous add Onsuccess listener
triggered when the API call succeeded.
Response dot place contains the fetched place object with all requested fields, and the selected place
typically is a mutable state that we created before and if we are using Viewmodels in in Xaml and in
Android views, it's a live data.
The camera position state controls the maps view zooms to the selected location.
Let me run our application and see the places API in action.
Oops.
We have this error for linking reference.
Scroll up style attribute and it's not found.
The corner family corner size are from the material theme dependency so build.gradle file.
Open it, then paste this dependency for material theme in order to solve this error.
Sync.
Now build the project and clean the project.
Run the application and let's let's see the places API.
Here we go.
This is our application search places.
Let me search for example times.
Here we have an error.
If I type anything, nothing changed except that there are there are Letters that appear in this search
bar.
So I think the the on value change is the problem here.
The search query.
You see guys, I am um I'm getting the wrong one.
So set the places query equals to the new query.
Run again our application.
Let's search places for example Times Square.
You see guys the suggestions we have five suggestions.
Uh, this is in Dubai.
This is in Hong Kong.
This is in New York, in New York City, in USA, in Manhattan.
Let me click on it.
And you can see guys that we have this very, very good example about getting the places.
And there is a new marker called here and Times Square, Manhattan, New York City.
We get information also, uh, we we, uh, we get a lot of things using this search places.
So this is the power of using places API.
Let me search another place.
And by the way, we are using this map overlay.
So don't be, uh, confused.
This is the map overlay from the previous videos over New York.
Let me.
Burj Khalifa, Burj Khalifa, this is the Burj Khalifa marker.
It's in Dubai.
And here we go.
So congratulations, guys.
This is our lovely application with this suggestions and search places.
It's a very, very important.
This is a very, very exciting and very complex application.
By the way, many developers had errors in this API.