Welcome back.
In this section we're going to deal with gestures of the map.
Let's start by the click or tap gesture which is a single tap on the map.
So for example if the user clicks on the map what we need to do, there are a lot of things we can do.
So in this video we're going to learn how to handle the tap, how to handle the single click on the
map.
In order to do that, let me go up and inside the Google map parameter we need to specify another parameter
which is on map.
Click on map click.
What we need to do.
We can create a lat long, or we can create a logcat message, or show a toast, or tell the user that
we can create a marker.
We can position a marker inside it or get the lat long for any uh, for the tap position.
So for example, let me start with lat long which is a lambda expression parameter.
And here let me create a println or logcat log v tag and set.
You clicked lat long.
Remove those parentheses and here we go.
Let me run open the logcat and search for tag and let me click uh near Singapore.
So let me click on the map.
You can notice that you clicked the lat latitude and longitude.
This okay.
Let me allow the user to place a marker on map.
Click.
So for that.
Instead of creating this we can create a marker, specify the state marker state and set the position
to lat long.
There is a very important thing here.
We can't specify a composable.
Instead in inside the on map click screw.
So how to solve it?
We need to create a list of markers to hold the list of markers of the clicked position.
So state to hold the list of markers.
Val markers equals to remember mutable state of mutable state of lat long.
And now when we click on the map, instead of creating the markers, we need to store them inside the
list that we created.
So markers dot add lat long.
Now we need to display inside the scope of the Google map.
So here displaying the clicked displaying the clicked Markers.
Markers dot for each.
This is the lambda expression.
Create a marker and set the state for this marker.
Marker state and set the position to location.
You can create a title for this marker.
Marker at location.
Let me run and this is our application here.
The first marker I tapped.
This is the second marker.
This is the third marker.
This is the fourth marker.
And so on.
If I click on the marker you can notice that marker at lat long.
This is the lat long.
And this is the different location.
This is the different markers that I create.
Also I can click every where I need.
I can zoom, double tap to zoom in and add the marker by single click on the map.
So in this case I can set and I can place markers on the map with a single click.