WEBVTT

00:00.080 --> 00:01.120
Welcome back.

00:01.120 --> 00:03.680
Now let's continue with the retrofit.

00:03.680 --> 00:09.320
And in this video we're going to create the second part of retrofit package which is the directions

00:09.320 --> 00:10.120
response.

00:10.120 --> 00:13.360
Create a new class data class.

00:13.360 --> 00:16.880
Name it as directions response.

00:16.920 --> 00:23.720
Let's start with the routes which is of type list of routes.

00:23.720 --> 00:27.560
And let's define the data class routes here.

00:27.800 --> 00:34.320
Create a new data class called route and start with not routes.

00:34.360 --> 00:42.280
Start with route and val over view polyline which is of type polyline.

00:42.280 --> 00:49.560
And here another data class which is poly val points.

00:49.560 --> 00:51.280
It's of type string.

00:51.360 --> 00:59.200
If you imported the polyline from Google Maps, please remove it because I am going to import this data

00:59.200 --> 00:59.560
class.

00:59.560 --> 01:06.240
So Alt plus enter to import the class, not the model class that we create here.

01:06.240 --> 01:08.770
It's of type poly line.

01:08.810 --> 01:09.370
Okay.

01:09.570 --> 01:15.450
So in order to distinguish it I made as poly L capital okay.

01:15.490 --> 01:18.290
So to reuse this data class.

01:18.450 --> 01:26.490
So this data class use the root and this root data class use polyline which is the third data class.

01:26.730 --> 01:32.370
Now let's explain why we created those three data classes.

01:32.490 --> 01:39.130
These data classes model the structure of the response from the Google Maps Directions API.

01:39.330 --> 01:41.570
Go back to the response.

01:41.730 --> 01:45.490
And here we have the Geocoded points.

01:45.490 --> 01:53.490
If you if you remember the key and the value from JSON syntax the key and the value.

01:53.610 --> 01:58.450
And here we are referring to the root which is the list of root.

01:58.450 --> 02:07.890
And if you remember, this is the JSON syntax where every element refers in this list as a root element

02:07.890 --> 02:09.970
inside this root list.

02:09.970 --> 02:11.290
So this is the array.

02:11.530 --> 02:16.330
Every element in this array correspond to the root elements.

02:16.370 --> 02:16.890
Okay.

02:17.090 --> 02:21.370
If you scroll down, you will get those roots.

02:21.370 --> 02:30.890
And if you click on Prettyprint it will define maybe would be better, but you can use different websites

02:30.890 --> 02:32.570
in order to identify it.

02:32.570 --> 02:39.610
So please refer to the previous videos in order in order to learn more about JSON syntax.

02:39.810 --> 02:48.050
But I am showing you how to, uh, to learn the response and how to model the response.

02:48.050 --> 02:49.010
The routes.

02:49.010 --> 02:55.890
And this is a list of routes I defined a model class called route, which is of the which is of type

02:55.930 --> 02:57.330
overview polyline.

02:57.490 --> 03:04.930
If we go here we have the polyline and the polyline gives us the points.

03:04.930 --> 03:09.570
So every polyline have or has the points okay.

03:09.770 --> 03:15.010
So here again guys I get the polyline polyline and so on.

03:15.010 --> 03:22.860
So every route contains polyline that should be displayed in our application.

03:23.060 --> 03:32.420
So the purpose representing the entire response from the directions API, the routes value a list of

03:32.420 --> 03:37.660
possible routes usually contains one route unless you request alternatives.

03:37.860 --> 03:39.140
Why a list?

03:39.180 --> 03:46.660
The API can return multiple route options if you set alternatives equals to true in your request.

03:46.820 --> 03:48.020
Other common fields.

03:48.020 --> 03:51.700
The status you can define the status if you go up.

03:51.980 --> 03:53.860
So let me scroll up.

03:54.020 --> 03:58.740
If you notice here we have routes.

03:58.780 --> 04:03.260
If you scroll down we can get the statuses okay.

04:03.500 --> 04:13.420
So again guys you can add more and more things like status warning waypoints, order and so on.

04:13.460 --> 04:21.180
But I'm showing you the most important and simple thing from API response.

04:21.180 --> 04:30.220
The route represents a single route between origin and destination, so this is the single route between

04:30.340 --> 04:32.660
origin and destination.

04:32.820 --> 04:43.300
The overview polyline contains this for the single route, and the overview polyline contains the encoded

04:43.300 --> 04:46.580
polyline path of the entire route.

04:46.620 --> 04:47.340
Legs.

04:47.420 --> 04:49.100
List of route segments.

04:49.100 --> 04:50.020
Bounds.

04:50.060 --> 04:54.380
Geographic rectangle that contains the entire route.

04:54.700 --> 04:57.780
The Copyright's attribution text.

04:57.860 --> 04:58.860
Warnings.

04:58.860 --> 05:01.340
Any route specific warnings.

05:01.380 --> 05:02.100
Fair.

05:02.300 --> 05:03.420
Public transit.

05:03.460 --> 05:03.860
Fair.

05:03.900 --> 05:05.780
Information, if applicable.

05:05.820 --> 05:13.260
Okay, so there are a lot of things you can implement in this JSON response.

05:13.300 --> 05:13.820
Okay.

05:14.100 --> 05:24.180
The polyline contains the compressed representation of the route's path points and encoded string using

05:24.340 --> 05:26.700
Google's polyline algorithm.

05:26.740 --> 05:28.380
Highly compressed format.

05:28.380 --> 05:31.340
Reduces data size significantly.

05:31.540 --> 05:34.820
Needs to be decoded before use on a map.

05:34.980 --> 05:40.430
For example, included encoded string might look like this.

05:40.470 --> 05:41.310
Encoded.

05:41.550 --> 05:42.670
So scroll down.

05:42.670 --> 05:45.310
And this is the encoded text okay.

05:45.510 --> 05:50.910
Now I want from you to understand why this structure matters.

05:51.150 --> 05:58.350
For efficiency the polyline encoding dramatically reduces data transfer size flexibility.

05:58.350 --> 06:05.550
The nested structure allows for complex route information extensibility.

06:05.750 --> 06:15.110
Easy to add more fields as you need growth and Kotlin data classes provide compile time checking.

06:15.150 --> 06:22.150
Most real world implementations include more fields, for example status error message, legs bound,

06:22.190 --> 06:24.430
copyrights warning, and others.

06:24.430 --> 06:30.390
But we are interested in this simple API response.

06:30.390 --> 06:34.750
Later, we're going to add more and more things like the waypoints.

06:34.750 --> 06:42.590
So here we have created the three data classes and the Data Directions Service interface.
