Our mission is to transform this ugly response into something visible on the map.
So I'm going to show you how to transform this ugly JSON response into routes displayed between two
markers and destinations.
Okay, so let's do it guys.
In the previous videos, and as we learned before, in order to implement retrofit, we have three sections
three things we need to work on it on them.
The first thing is the interface the directions service, the model class or the data class.
And the last part is the retrofit instance.
Let's start with this interface.
Directions surface.
This interface defines a contract for making requests to the Google Maps Directions API.
Using retrofit.
The interface declares an interface that retrofit will implement to make HTTP requests.
All methods in this interface will be converted to HTTP calls.
So I want from you to understand that all methods in this interface will be converted to HTTP calls.
Let's start with at a get and here we need to get from directions JSON.
So get from direct maps API directions JSON.
You can consider this is the base URL you can consider.
This is the the endpoint and so on okay so here we are using the and we are implementing the endpoints
maps API directions JSON.
You can implement direction JSON.
You can implement API directions JSON.
You can implement maps API directions JSON as you want okay.
So in order to make it simple I'm showing you here that directions JSON.
This is special.
And you can consider this as the base URL.
So this is the base URL.
This is the end point.
So here and point.
Okay.
And here we go.
Okay.
We need to import a get request.
So add get.
It's not generated here.
And it gives me an error.
So unresolved the unresolved reference.
This is due maybe to the latest versions of retrofit which is snapshot.
Um I'm going to downgrade to 9.9.
2.9.0.
This is more stable.
So let me downgrade.
Also you can remove this implementation sync now and it's better.
Alt plus enter to import the class A class get.
And here we go.
We imported retrofit to HTTP get.
Okay.
We need to use suspend function get directions.
This annotation get specifies the Get request the endpoint directions slash JSON relative to the base
URL that we created and you you provide when building retrofit.
This is.
This corresponds to Google's Directions API endpoint.
So as I told you this is the the URL.
This is the base URL.
This is the endpoint.
And those are the variables in this application.
We're gonna use those three parts base URL endpoint and the variables and parameters in order to create
the whole API request and get the response from the server.
Then we use the suspend function.
Suspend marks.
This as a coroutine function can be called from coroutines or suspend functions providing non-blocking
asynchronous execution.
The parameters with query annotation.
Here we have the query annotation Alt+ enter to import the destination origin and key.
If we go back to here, we have three parameters destination, origin and key.
The first query is origin maps to the origin query parameter in the API request should be a string in
format latitude, comma, longitude or a place id.
For example 37.77 comma minus one 22.41.
The destination parameter maps to the destination query parameter as we did here in the material.
Same format requirements as origin.
We can use a parameters for the longitude and latitude in form of latitude, longitude, or the place
id.
You can add waypoints later for adding more waypoints between the origin and destination in the next
videos, and when adding multiple markers and destination between multiple markers and the API key parameter
required for authentication with Google's API should be your Google Maps API key.
Never hard code this injected at run time.
Okay, as I showed you, you can get it from here in the API and show key.
The return type should be directions response.
The API response will be parsed into a response object.
You need to define this data class to match Google's response format typically includes routes, lags,
steps, polyline data, and etc. so this is our interface direction service.
In the next video, we'll continue with the retrofit section and we're going to create.