WEBVTT

00:00.080 --> 00:01.040
Welcome back.

00:01.080 --> 00:06.120
In this section we're going to deal with gestures of the map.

00:06.240 --> 00:12.480
Let's start by the click or tap gesture which is a single tap on the map.

00:12.600 --> 00:20.240
So for example if the user clicks on the map what we need to do, there are a lot of things we can do.

00:20.440 --> 00:28.520
So in this video we're going to learn how to handle the tap, how to handle the single click on the

00:28.520 --> 00:29.000
map.

00:29.000 --> 00:40.040
In order to do that, let me go up and inside the Google map parameter we need to specify another parameter

00:40.240 --> 00:42.480
which is on map.

00:42.520 --> 00:45.080
Click on map click.

00:45.200 --> 00:46.520
What we need to do.

00:46.720 --> 00:57.720
We can create a lat long, or we can create a logcat message, or show a toast, or tell the user that

00:58.200 --> 01:00.400
we can create a marker.

01:00.600 --> 01:08.600
We can position a marker inside it or get the lat long for any uh, for the tap position.

01:08.600 --> 01:15.160
So for example, let me start with lat long which is a lambda expression parameter.

01:15.280 --> 01:24.160
And here let me create a println or logcat log v tag and set.

01:24.200 --> 01:26.640
You clicked lat long.

01:26.800 --> 01:29.720
Remove those parentheses and here we go.

01:29.880 --> 01:37.800
Let me run open the logcat and search for tag and let me click uh near Singapore.

01:38.000 --> 01:39.880
So let me click on the map.

01:40.000 --> 01:46.400
You can notice that you clicked the lat latitude and longitude.

01:46.680 --> 01:47.920
This okay.

01:47.960 --> 01:52.560
Let me allow the user to place a marker on map.

01:52.560 --> 01:53.320
Click.

01:53.320 --> 01:54.440
So for that.

01:54.480 --> 02:03.680
Instead of creating this we can create a marker, specify the state marker state and set the position

02:03.840 --> 02:05.880
to lat long.

02:06.040 --> 02:08.890
There is a very important thing here.

02:08.890 --> 02:11.650
We can't specify a composable.

02:11.650 --> 02:16.330
Instead in inside the on map click screw.

02:16.370 --> 02:18.210
So how to solve it?

02:18.250 --> 02:28.370
We need to create a list of markers to hold the list of markers of the clicked position.

02:28.370 --> 02:33.330
So state to hold the list of markers.

02:33.450 --> 02:43.690
Val markers equals to remember mutable state of mutable state of lat long.

02:43.730 --> 02:52.290
And now when we click on the map, instead of creating the markers, we need to store them inside the

02:52.290 --> 02:53.810
list that we created.

02:54.090 --> 02:58.330
So markers dot add lat long.

02:58.490 --> 03:04.050
Now we need to display inside the scope of the Google map.

03:04.050 --> 03:10.490
So here displaying the clicked displaying the clicked Markers.

03:10.490 --> 03:12.490
Markers dot for each.

03:12.730 --> 03:14.410
This is the lambda expression.

03:14.410 --> 03:18.570
Create a marker and set the state for this marker.

03:18.610 --> 03:22.810
Marker state and set the position to location.

03:22.850 --> 03:25.850
You can create a title for this marker.

03:25.890 --> 03:27.730
Marker at location.

03:27.730 --> 03:31.170
Let me run and this is our application here.

03:31.570 --> 03:33.610
The first marker I tapped.

03:33.730 --> 03:35.690
This is the second marker.

03:35.730 --> 03:37.490
This is the third marker.

03:37.730 --> 03:39.490
This is the fourth marker.

03:39.490 --> 03:40.530
And so on.

03:40.530 --> 03:45.050
If I click on the marker you can notice that marker at lat long.

03:45.090 --> 03:46.490
This is the lat long.

03:46.730 --> 03:49.370
And this is the different location.

03:49.610 --> 03:52.770
This is the different markers that I create.

03:52.770 --> 03:56.450
Also I can click every where I need.

03:56.610 --> 04:03.450
I can zoom, double tap to zoom in and add the marker by single click on the map.

04:03.450 --> 04:13.890
So in this case I can set and I can place markers on the map with a single click.
