Maybe you are wondering why we use retrofit with Google Maps.
Again, retrofit is not strictly required to use directions API, but it offers several advantages over
the traditional Google Maps services.
Java client.
So again guys, if you use this library, it's sufficient and there is no need to use retrofit with
API calls.
But in as I told you, for more efficient and professional and reliable calls and responses and network
calls, I'm using retrofit.
Retrofit is type safe HTTP client for Android and Java, handling all low level HTTP work.
I want to show you something.
If you go to directions API overview or the new documentation documentations with directions API, you
can get directions for several modes of transportation such as transit, driving, walking, and bicycle.
The most important part here is how the directions API work.
The directions API returns the most efficient routes when calculating directions.
The product factors in the following travel elements when determining the most efficient route the travel
time, distance, and number of turns.
This depends on the algorithm of the directions API and how to calculate the most efficient route using
these three variables the travel time, which is the primary distance, and the number of turns.
Now I want from you to focus with me.
Please pay attention.
Here we have this API call.
The following example request returns driving directions from Toronto, Ontario to Montreal, Quebec
in JSON format.
Here I am requesting this is the base URL.
Did you remember base URL when working with retrofits with retrofit and API calls, the response we
have the base URL and the endpoint and the variables of course.
So this is the endpoint.
And here we have the variable destination Montreal.
The origin is Toronto.
And the key your API key.
Let me copy this code sample copy it.
And I want from you to focus with me here please please guys let me make here a new package.
Name it as retrofit.
Inside this retrofit create a new Kotlin interface.
Name it as directions, services or service.
Please write those notes down.
And here we have this API call.
This is the base URL.
So this is the base URL.
And those are the variables okay.
Now let me change this API key with the API key that we have in the Google Maps platform.
Click show key.
copy it and replace it with this.
Let's copy this API call and to here click go.
And here we go.
We have a JSON response that Geocoder status okay.
The types locality political and other variables.
The routes we have the description for the North East and the South West copyrights powered by Google
legs.
We have endpoints start point and the points between the location Toronto and Montreal.
So the origin is Toronto and the Montreal is destination.
Okay.
All these codes, all these variables, all the JSON response will be transformed into something visible
on the map.
This is what we're going to create.
This is our job to transform this response into the route displayed on the map.