The next step after creating the directions repository is to create the class that implements this interface.
So here, as we learned before, we need to create directions repository implementation.
This class implements the directions repository and we need to add some parameters for the constructor.
Also, we need to use the inject annotation in order to inject the constructor.
So alt plus enter to import the inject from Javax dot inject.
Inject.
And we need to inject the constructor with two parameters.
The first one is the private val api key, which is of type string, and the second one is of type directions.
Surface Alt+ enter to import the direction surface.
We need to implement the two functions Alt+ enter to implement the members.
Get root and get root for multiple markers.
Here we go.
Those are the two functions.
Let's start with the first one which is the get root return.
Try.
Let's start with val origin str which is string.
And here we need to fetch the origin as a string because when making an API call and we need to get
the strings, we use strings and not any other objects like lat longs.
So we need to convert the lat long which is the origin into string.
It's very simple.
Here we get the first coordinate which is latitude and the second is the longitude.
Okay.
This is for origin.
Let's start with destination str.
Destination latitude and destination dot longitude.
We are converting the origin and destination which are of type latitude and longitude.
Lat long.
Objects into strings in order to put them into the API call.
Here close it with catch exception and return null.
Then close this.
Here we go.
Let's continue with return a try.
We need to return a list of lat long.
So here inside the try we need to get the response.
So response equals to.
Let's call the direction service interface dot get directions function specifying three parameters the
origin destination and the API key.
Again guys this is the first step converting origin and destination into strings for API call.
The second step is the API call itself by calling the response that the directions service dot get directions
function, and we have to pass three parameters.
This function makes a network request to get directions between the points.
Uses the previously created directions service, including an API key for authentication.
The third step here is response processing.
We request this from the server and we get the response into the response variable.
So here we store this call inside this response variable.
And let's process this response.
So let's use this variable in order to extract the points and the strings and transform every point
into a lat long object.
So response dot which is a list of roots dot first or null.
Overview polyline dot points.
Dot lat polyline or polyline util dot code.
Don't worry, we're gonna explain everything.
The encoded path dot map and set lat long for every point.
Create a lat long object having the latitude and longitude.
The response dot dot first or null.
Overview polyline dot points accesses the first route in the response.
So this is the function that allows us to access the first route in the response if available.
Getting the overview polyline which contains encoded Polly points.
Okay, so this will access the first route in the response.
I want from you to write those notes down please, because these are very important and helps you,
uh, to recognize and remember what are and, uh, how why we used those codes.
Okay.
This will get the overview polyline containing encoded points.
The encoded points are of type string.
We need to extract the points string encoded polyline format and access this string and transform every
point into lat long.
So here we are using the polyline encoding.
So the first the fourth step is polyline decoding.
Uses Polly utils decode.
This is from Google Maps util.
To decode the polyline string maps each decoded point to a lat long object.
The lat block ensures this only happens if points exist.
If there is an error here, we need to return null.
For example, if the network call fails, response has no routes.
Polyline is missing or invalid.
Any other exception occurs.
Polyline encoding using Google efficient polyline encoding algorithm to represent the route with minimal
data.
Okay, so this is a very important thing we should use in order to get the response in form of strings.
Then processing this response and transform the strings into latitude and longitude lat long points.