Welcome back.
When the user clicks on the map, there is a new marker created but not saved to the firestore.
When the user clicks on request right, this marker will be uploaded to the firestore and saved.
So if we run the application again, the marker in Bolivia is being saved to the firestore and received
during the application launch.
Again, if I want to draw the route between the current location and the selected location, I need
to select the marker and click Draw Route.
But there is this is a problem here because there is a no route between the selected marker from Firestore
and my current location.
If I drop a new marker here in Paraguay, select it And click draw root.
The root is fetched successfully.
So the problem is when the user clicks on the firestore markers.
Let me go back to the Uber clone.
And here we need to set the selected marker where variable to the selected marker from Firestore.
So I am teaching you how to test your applications.
Here we have an error when clicking on any marker of Firestore markers.
There is no root here.
We have successfully drawing route between any marker on the map that it is not saved or fetched to
Firebase Firestore.
So how to solve it.
We need to check the markers of Firestore.
Go back to Uber Clone map.
And here the markers list.
Let me change it from markers to markers in Firestore.
Scroll up here.
Markers in Firestore.
Scroll down markers in Firestore.
For each marker go and create a marker and set the title to the marker dot title.
Or you can simply make it as Firestore marker.
Set the snippet to marker coordinates and set on.
Click ViewModel dot.
Set selected location to the selected marker okay to Latlong and here return false.
Now I want to show you something.
Let me run.
If I select any marker, we get Firestore marker.
You can change it to Marker title.
So for example marker dot title okay.
So here you can customize the marker as you want.
Let me click Italy.
Nothing displayed because there is an error in the marker title.
If we go back here to Italy we have only latitude and longitude.
If I need to get the title of the document, it's very simple.
So here is a trick.
The ID of the document represent it or its name.
So here let me change the marker dot title to marker.id run again.
Click on Italy and you get Italy London, Paris.
And here we in Bolivia we have the destination because the name of the marker is set it to a destination
with lat and long.
Okay.
So here you can customize the marker as you want.
Also, you can drop a marker here and when saving to Firestore you can request from the user what name
you should or he should name it for this newly created marker.
Let's test our algorithm and logic.
So click on this saved location and retrieved marker from Firebase Firestore and request the route.
If I request the route.
So there is no route displayed between the current position and the selected marker.
Even though let me test the selected marker.
So here inside the marker in Firestore when I click on any marker, I added this Logcat tag and the
selected marker to let log if I run the application again and select any marker.
Go to Filter Tag and here the current position and the selected lat long is displayed correctly.
Again let me check this.
If I click Bolivia that the lat long is displayed correctly.
So the the problem is in the algorithm.
Let me scroll down here inside the expandable fab in Uber clone map on draw route.
Here we have.
If marker position is not null and this is not the case, we have the marker position or the marker
retrieved from Firestore.
So in this case we can change it to selected location does not equal to null.
Let me run again select Bolivia.
Click Draw Route and to check the look at here.
The selected is not null but the application crashes again.
Selected location.
Here the ViewModel dot fetch route from current position to marker.
We don't need the marker position.
We need the selected location.
Dot two exclamation marks.
Run again because we are testing the selected location and not the marker position.
The marker position is any marker drawn by the user.
When the when he clicks on the map, the selected marker is the marker that it is saved and fetched
from Firebase Firestore.
Draw route.
And here we go.
Congratulations guys.
Now we can save markers.
We upload rides.
We upload request write request.
And the user and the driver can fetch the route between the current position and the destination or
the requested ride.