WEBVTT

00:00.080 --> 00:05.600
Maybe you are wondering why we use retrofit with Google Maps.

00:05.840 --> 00:14.840
Again, retrofit is not strictly required to use directions API, but it offers several advantages over

00:14.840 --> 00:17.120
the traditional Google Maps services.

00:17.160 --> 00:18.280
Java client.

00:18.560 --> 00:26.760
So again guys, if you use this library, it's sufficient and there is no need to use retrofit with

00:26.880 --> 00:27.960
API calls.

00:27.960 --> 00:37.960
But in as I told you, for more efficient and professional and reliable calls and responses and network

00:37.960 --> 00:40.720
calls, I'm using retrofit.

00:40.760 --> 00:49.240
Retrofit is type safe HTTP client for Android and Java, handling all low level HTTP work.

00:49.280 --> 00:51.400
I want to show you something.

00:51.440 --> 00:59.560
If you go to directions API overview or the new documentation documentations with directions API, you

00:59.560 --> 01:06.680
can get directions for several modes of transportation such as transit, driving, walking, and bicycle.

01:06.800 --> 01:14.230
The most important part here is how the directions API work.

01:14.510 --> 01:21.270
The directions API returns the most efficient routes when calculating directions.

01:21.470 --> 01:29.230
The product factors in the following travel elements when determining the most efficient route the travel

01:29.270 --> 01:32.350
time, distance, and number of turns.

01:32.630 --> 01:40.470
This depends on the algorithm of the directions API and how to calculate the most efficient route using

01:40.510 --> 01:47.710
these three variables the travel time, which is the primary distance, and the number of turns.

01:47.750 --> 01:51.110
Now I want from you to focus with me.

01:51.270 --> 01:52.950
Please pay attention.

01:52.990 --> 01:56.070
Here we have this API call.

01:56.230 --> 02:05.630
The following example request returns driving directions from Toronto, Ontario to Montreal, Quebec

02:05.630 --> 02:07.070
in JSON format.

02:07.110 --> 02:11.030
Here I am requesting this is the base URL.

02:11.230 --> 02:18.750
Did you remember base URL when working with retrofits with retrofit and API calls, the response we

02:18.850 --> 02:23.450
have the base URL and the endpoint and the variables of course.

02:23.610 --> 02:25.610
So this is the endpoint.

02:25.610 --> 02:30.610
And here we have the variable destination Montreal.

02:30.730 --> 02:33.450
The origin is Toronto.

02:33.610 --> 02:36.810
And the key your API key.

02:36.930 --> 02:40.930
Let me copy this code sample copy it.

02:41.170 --> 02:49.330
And I want from you to focus with me here please please guys let me make here a new package.

02:49.370 --> 02:51.690
Name it as retrofit.

02:51.690 --> 02:56.770
Inside this retrofit create a new Kotlin interface.

02:56.810 --> 03:01.170
Name it as directions, services or service.

03:01.210 --> 03:04.650
Please write those notes down.

03:04.810 --> 03:08.290
And here we have this API call.

03:08.330 --> 03:10.490
This is the base URL.

03:10.610 --> 03:13.170
So this is the base URL.

03:13.410 --> 03:17.170
And those are the variables okay.

03:17.330 --> 03:26.010
Now let me change this API key with the API key that we have in the Google Maps platform.

03:26.010 --> 03:27.530
Click show key.

03:27.800 --> 03:31.120
copy it and replace it with this.

03:31.240 --> 03:35.880
Let's copy this API call and to here click go.

03:35.880 --> 03:37.080
And here we go.

03:37.120 --> 03:41.600
We have a JSON response that Geocoder status okay.

03:41.880 --> 03:46.280
The types locality political and other variables.

03:46.280 --> 03:55.240
The routes we have the description for the North East and the South West copyrights powered by Google

03:55.440 --> 03:56.240
legs.

03:56.280 --> 04:05.880
We have endpoints start point and the points between the location Toronto and Montreal.

04:06.000 --> 04:12.240
So the origin is Toronto and the Montreal is destination.

04:12.280 --> 04:12.760
Okay.

04:13.040 --> 04:24.840
All these codes, all these variables, all the JSON response will be transformed into something visible

04:24.840 --> 04:25.800
on the map.

04:25.800 --> 04:28.880
This is what we're going to create.

04:28.880 --> 04:36.640
This is our job to transform this response into the route displayed on the map.
