Welcome back.
Now let's continue with the retrofit.
And in this video we're going to create the second part of retrofit package which is the directions
response.
Create a new class data class.
Name it as directions response.
Let's start with the routes which is of type list of routes.
And let's define the data class routes here.
Create a new data class called route and start with not routes.
Start with route and val over view polyline which is of type polyline.
And here another data class which is poly val points.
It's of type string.
If you imported the polyline from Google Maps, please remove it because I am going to import this data
class.
So Alt plus enter to import the class, not the model class that we create here.
It's of type poly line.
Okay.
So in order to distinguish it I made as poly L capital okay.
So to reuse this data class.
So this data class use the root and this root data class use polyline which is the third data class.
Now let's explain why we created those three data classes.
These data classes model the structure of the response from the Google Maps Directions API.
Go back to the response.
And here we have the Geocoded points.
If you if you remember the key and the value from JSON syntax the key and the value.
And here we are referring to the root which is the list of root.
And if you remember, this is the JSON syntax where every element refers in this list as a root element
inside this root list.
So this is the array.
Every element in this array correspond to the root elements.
Okay.
If you scroll down, you will get those roots.
And if you click on Prettyprint it will define maybe would be better, but you can use different websites
in order to identify it.
So please refer to the previous videos in order in order to learn more about JSON syntax.
But I am showing you how to, uh, to learn the response and how to model the response.
The routes.
And this is a list of routes I defined a model class called route, which is of the which is of type
overview polyline.
If we go here we have the polyline and the polyline gives us the points.
So every polyline have or has the points okay.
So here again guys I get the polyline polyline and so on.
So every route contains polyline that should be displayed in our application.
So the purpose representing the entire response from the directions API, the routes value a list of
possible routes usually contains one route unless you request alternatives.
Why a list?
The API can return multiple route options if you set alternatives equals to true in your request.
Other common fields.
The status you can define the status if you go up.
So let me scroll up.
If you notice here we have routes.
If you scroll down we can get the statuses okay.
So again guys you can add more and more things like status warning waypoints, order and so on.
But I'm showing you the most important and simple thing from API response.
The route represents a single route between origin and destination, so this is the single route between
origin and destination.
The overview polyline contains this for the single route, and the overview polyline contains the encoded
polyline path of the entire route.
Legs.
List of route segments.
Bounds.
Geographic rectangle that contains the entire route.
The Copyright's attribution text.
Warnings.
Any route specific warnings.
Fair.
Public transit.
Fair.
Information, if applicable.
Okay, so there are a lot of things you can implement in this JSON response.
Okay.
The polyline contains the compressed representation of the route's path points and encoded string using
Google's polyline algorithm.
Highly compressed format.
Reduces data size significantly.
Needs to be decoded before use on a map.
For example, included encoded string might look like this.
Encoded.
So scroll down.
And this is the encoded text okay.
Now I want from you to understand why this structure matters.
For efficiency the polyline encoding dramatically reduces data transfer size flexibility.
The nested structure allows for complex route information extensibility.
Easy to add more fields as you need growth and Kotlin data classes provide compile time checking.
Most real world implementations include more fields, for example status error message, legs bound,
copyrights warning, and others.
But we are interested in this simple API response.
Later, we're going to add more and more things like the waypoints.
So here we have created the three data classes and the Data Directions Service interface.