Welcome back.
Let's continue with add marker function.
Start with try and catch val data equals to hash map of.
Set the lat to marker dot latitude longitude to marker longitude.
Here you should pay attention to this important uh note can't access Google dot protobuf and the lat
long.
This is not the correct thing we imported, so we need to remove this import alt plus enter to import
the class and don't import comment google.com type we.
We need to import Google Android maps module okay, so remove the previous one and add this.
Because this is a very important thing.
We imported wrong class Firebase dot collection and set the markers.
Don't worry I will lecture everything.
Just follow me now.
Document name dot Set data dot await.
Let's start from above.
Override.
You are overriding the function declared in marker repository interface, and suspend means that this
function suspends and is suspending function.
It can be called inside coroutines without blocking the main thread.
The parameters are markers and name marker of type Latlong and the name is of type string.
Try block.
You wrap the function in try catch so you can catch any errors like network errors.
Rethrow them as your own marker exception.
Um handling.
So here you can handle the errors and val data equals to HashMap.
You create a HashMap to represent what you want to store.
In Firestore.
The Firebase Firestore collection markers get.
The markers collection will be created if it is uh not exist.
Document document name creates or overwrite that document with ID equals to name.
So the ID of the collection with would be, uh, the ID of the collection would be markers, the ID
of the document would be the name, and the fields would be the data.
So here I'm using the set.
Set the content of the document to your map latitude and longitude.
If the document exists it overrides it.
So again guys Firebase dot collection gets the markers collection and will be created.
If it doesn't exist.
Document name create or overwrite the document with ID equals to name.
This is important if you pass uh home as name and document ID will be home.
Set data.
Set the content of the document to your map latitude plus longitude.
If your document exists, it overrides it and await.
Since Firestore is asynchronous, you await the result.
This is a suspend function.
This suspends the coroutine until the operation completes.
If this succeeds, the function And normally.
Otherwise we need to throw exceptions using the catch block.
So if anything goes wrong like no internet Firestore permission error, bad arguments, you catch the
exception and throw your own custom exception with the message.
For example let's start with exception.
And here for example print stack trace.
Okay.
This is our function.
Alt plus enter to implement the members add markers.
We need to to check this error because the lat long is of type uh it's missing type of.
And uh we imported it wrong in interface.
Okay.
So you notice that Google type.lat long.
We need to copy this and replace it in the Firebase or the marker repository interface.
And this will solve the error.
Okay.
The problem was importing the wrong class of lat long.