WEBVTT

00:00.120 --> 00:00.920
Welcome back.

00:01.080 --> 00:03.840
Let's continue with add marker function.

00:03.840 --> 00:12.000
Start with try and catch val data equals to hash map of.

00:12.280 --> 00:19.520
Set the lat to marker dot latitude longitude to marker longitude.

00:19.560 --> 00:29.080
Here you should pay attention to this important uh note can't access Google dot protobuf and the lat

00:29.120 --> 00:29.480
long.

00:29.520 --> 00:37.760
This is not the correct thing we imported, so we need to remove this import alt plus enter to import

00:37.760 --> 00:42.440
the class and don't import comment google.com type we.

00:42.800 --> 00:51.680
We need to import Google Android maps module okay, so remove the previous one and add this.

00:51.720 --> 00:54.560
Because this is a very important thing.

00:54.600 --> 01:01.920
We imported wrong class Firebase dot collection and set the markers.

01:02.120 --> 01:05.120
Don't worry I will lecture everything.

01:05.240 --> 01:06.440
Just follow me now.

01:06.680 --> 01:12.420
Document name dot Set data dot await.

01:12.460 --> 01:13.780
Let's start from above.

01:13.820 --> 01:14.620
Override.

01:14.620 --> 01:21.860
You are overriding the function declared in marker repository interface, and suspend means that this

01:21.860 --> 01:24.940
function suspends and is suspending function.

01:24.940 --> 01:29.380
It can be called inside coroutines without blocking the main thread.

01:29.580 --> 01:37.420
The parameters are markers and name marker of type Latlong and the name is of type string.

01:37.700 --> 01:38.740
Try block.

01:38.900 --> 01:44.620
You wrap the function in try catch so you can catch any errors like network errors.

01:44.660 --> 01:48.700
Rethrow them as your own marker exception.

01:48.940 --> 01:50.500
Um handling.

01:50.500 --> 01:56.700
So here you can handle the errors and val data equals to HashMap.

01:56.740 --> 02:01.020
You create a HashMap to represent what you want to store.

02:01.020 --> 02:02.100
In Firestore.

02:02.340 --> 02:06.420
The Firebase Firestore collection markers get.

02:06.420 --> 02:10.780
The markers collection will be created if it is uh not exist.

02:10.820 --> 02:17.340
Document document name creates or overwrite that document with ID equals to name.

02:17.340 --> 02:24.810
So the ID of the collection with would be, uh, the ID of the collection would be markers, the ID

02:24.810 --> 02:30.450
of the document would be the name, and the fields would be the data.

02:30.450 --> 02:32.930
So here I'm using the set.

02:33.050 --> 02:37.530
Set the content of the document to your map latitude and longitude.

02:37.530 --> 02:41.010
If the document exists it overrides it.

02:41.010 --> 02:48.290
So again guys Firebase dot collection gets the markers collection and will be created.

02:48.290 --> 02:50.170
If it doesn't exist.

02:50.210 --> 02:55.570
Document name create or overwrite the document with ID equals to name.

02:55.810 --> 03:02.010
This is important if you pass uh home as name and document ID will be home.

03:02.050 --> 03:03.450
Set data.

03:03.770 --> 03:08.730
Set the content of the document to your map latitude plus longitude.

03:08.730 --> 03:13.010
If your document exists, it overrides it and await.

03:13.010 --> 03:17.450
Since Firestore is asynchronous, you await the result.

03:17.450 --> 03:20.370
This is a suspend function.

03:20.370 --> 03:25.050
This suspends the coroutine until the operation completes.

03:25.210 --> 03:29.190
If this succeeds, the function And normally.

03:29.390 --> 03:34.670
Otherwise we need to throw exceptions using the catch block.

03:34.910 --> 03:43.030
So if anything goes wrong like no internet Firestore permission error, bad arguments, you catch the

03:43.430 --> 03:48.310
exception and throw your own custom exception with the message.

03:48.550 --> 03:52.710
For example let's start with exception.

03:52.830 --> 03:56.950
And here for example print stack trace.

03:56.990 --> 03:57.590
Okay.

03:57.710 --> 03:59.710
This is our function.

03:59.750 --> 04:03.110
Alt plus enter to implement the members add markers.

04:03.430 --> 04:11.590
We need to to check this error because the lat long is of type uh it's missing type of.

04:11.750 --> 04:16.390
And uh we imported it wrong in interface.

04:16.430 --> 04:16.750
Okay.

04:16.790 --> 04:19.790
So you notice that Google type.lat long.

04:20.030 --> 04:26.790
We need to copy this and replace it in the Firebase or the marker repository interface.

04:26.990 --> 04:29.270
And this will solve the error.

04:29.310 --> 04:29.830
Okay.

04:30.150 --> 04:34.150
The problem was importing the wrong class of lat long.
