Hello developers, and congratulations!
This is an amazing application.
You reviewed many concepts like Firebase retrofit API calls, Firestore, hilt, dependency Injection,
Google Maps and you deal with many complex UI and many complex things in Android development.
Also don't miss the clean architecture you followed.
Okay, so congratulations and let's continue adding new features to our application.
Here we requested the route between the local or the current location and the selected marker on Firebase
Firestore.
Now let us add a new feature for multiple markers.
So we're going to display a route between multiple markers on the map.
So here there is no need for the the starting location, which is the current location.
You can add it by the way, or if we have, for example, a marker in Brazil and a marker in Venezuela.
So you can draw the route between the starting point and through the three markers Bolivia, Brazil
and Venezuela.
So this is the logic that we are going to work on for this purpose.
Let me start from the beginning.
We need to change the directions service.
And here we need to add the additional query which is the way points.
So way points and way points which is of type string equals to null okay.
Then the next step is the directions repository.
Here we created two markers.
The first one to methods get root, which is from the origin, which is the local and the current location
to the selected marker.
And here the route between multiple markers.
But this function needs to return a list of lat long.
The third step is to edit the directions repository implementation.
So here I'm showing you how how to add additional features.
If you think about a new feature and you want to add it to this application, you should pass through
those steps.
Okay guys.
So this is the overwrite suspend function.
We need to return a list of LA long.
And this is good.
Okay.
Now we need to remove this todo and start trying to get the and fetch the waypoints.
Start with try val in the same way as we did before.
The origin value.
The origin.
Variable.
Origin.
Latitude.
Origin.
Longitude.
I'm getting them from here from the passed parameter val destination.
Also in the same way, here we are transforming the origin and destination lat long objects into strings.
Now let me format waypoints for intermediate points val waypoints equals to.
If the size waypoints dot size greater than two, we can draw a destination or a route okay.
So optimize true.
We need to use this format.
This is from the format of the API call.
Waypoints dot sub list one waypoints.
Size minus one dot join string to string.
Set the separator and here set the ID eight dot latitude and longitude.
Here I'm formatting getting all waypoints and setting this request to add it to the API call.
So the waypoint remove the first one which is the origin, and get the separator between the points
and since and get the latitude and longitude.
Then we need to format the response.
So val response equals to the directions service dot get directions.
Set the origin to origin, destination to destination, str waypoints to waypoints and API key to API
key.
Then we need to return the response.
So here we need to return a uh a list of points.
So val points equals to response.
Set the overview polyline dot points and then return poly util.
This is what we used before in order to draw the path between the points and the others.
So map lat lat long.
Set the two parameters the latitude and longitude so it dot latitude and it dot longitude okay this
is the returning type.
Otherwise we need to catch.
So here catch close E exception and set this to return null okay.
So this is the idea behind getting route for multiple markers.
In the next video we're going to call this function and test it on our map.