WEBVTT

00:00.080 --> 00:02.520
Hello developers, and welcome back.

00:02.520 --> 00:10.160
Congratulations for building this amazing app and thank you for being patient with me.

00:10.160 --> 00:15.920
I hope you benefit from our courses and rate us five stars on Udemy.

00:16.200 --> 00:23.000
And I promise you, if you support me writing us five stars on Udemy, I'll continue adding more and

00:23.000 --> 00:26.800
more features and more and more videos to this course.

00:26.840 --> 00:31.240
Okay, now let's begin with our lesson.

00:31.240 --> 00:35.920
In this video I'm going to introduce something called directions API.

00:36.040 --> 00:41.120
Go to Google Cloud or Console.cloud.google.com.

00:41.280 --> 00:50.360
Select your project APIs and services, scroll down, search for directions API and choose it.

00:50.360 --> 00:58.080
Scroll down and make sure you enable it here so directions API is enabled.

00:58.400 --> 01:08.840
The Google Maps Directions API is a service that calculates directions between locations, including

01:08.840 --> 01:15.240
various modes of transportation, driving, walking, bicycling, or transit.

01:15.240 --> 01:20.680
So it's a very important feature we're going to add to our application.

01:20.920 --> 01:22.240
Go to the keys.

01:22.600 --> 01:27.480
And I think they are the same key as before.

01:27.520 --> 01:32.880
Click on show key and you'll get the same key API key as we did before.

01:33.160 --> 01:33.640
Okay.

01:33.840 --> 01:36.960
Now go back to our application.

01:37.080 --> 01:44.160
Make sure you added the maps compose and play services maps here.

01:44.360 --> 01:47.840
Scroll down and add the Google Maps services.

01:47.840 --> 01:56.960
And as you remember before we added Play services, maps, compose widgets and util, we can add here

01:56.960 --> 01:58.920
for directions.

01:58.960 --> 02:04.920
Com that Google Android Play Services maps sync now and here we go.

02:04.960 --> 02:07.840
Now I want from you to focus with me.

02:07.960 --> 02:12.120
We need to add retrofit in order to use directions.

02:12.120 --> 02:20.800
API retrofit is not strictly required to use the directions API, but it offers several advantages over

02:20.800 --> 02:23.280
the traditional Google Maps services.

02:23.280 --> 02:27.840
Java client that library used in the first couple of minutes.

02:28.000 --> 02:37.080
So here we're gonna add retrofit library in order to make connections more and more fast and reliable.

02:37.120 --> 02:44.640
Okay, so I'm gonna use retrofit in order to make the HTTP requests and calls.

02:44.680 --> 02:52.400
Being more and more professional, retrofit is a type safe HTTP client for Android, and Java handles

02:52.480 --> 03:01.360
all the low level HTTP work, connection pooling, threading, and etc. built on top of HTTP and native

03:01.360 --> 03:03.160
support for coroutines.

03:03.200 --> 03:09.800
Also, it provides cleaner error handling and more idiomatic Kotlin code.

03:09.840 --> 03:17.640
The official Google Maps services library is quite large, so here the services is quite large.

03:17.680 --> 03:19.330
It's about two megabytes.

03:19.370 --> 03:27.930
Retrofit plus is typically smaller if you're already using them, so you can use this in order to add

03:27.970 --> 03:30.010
the services for maps.

03:30.010 --> 03:33.250
Or you can use retrofit clients.

03:33.290 --> 03:42.290
Okay, so I'll show you the fastest and more professional way which using which is using retrofit.

03:42.290 --> 03:47.530
Go to download copy this implementation and paste it here.

03:47.810 --> 03:56.330
Then add the implementation for the G-Sync converter and you can use the HTTP three logging interceptor.

03:56.410 --> 04:04.850
We need the converter in order to make the serializing and deserializing for the objects, so retrofit

04:04.890 --> 04:12.850
ensures the type safety, coroutine support, apk size, impact customization, error handling, JSON

04:12.850 --> 04:14.730
parsing, and so on.

04:14.850 --> 04:19.170
Okay, the first thing we need to add is retrofit library.

04:19.170 --> 04:22.770
The second thing is the converter JSON.

04:22.810 --> 04:28.370
You can select the other converters, for example, go to converters.

04:28.610 --> 04:31.130
Jason Jackson, mochi and so on.

04:31.130 --> 04:32.850
I preferred Mochi and Jason.

04:32.850 --> 04:38.210
They are most reliable and the most efficient converters.

04:38.370 --> 04:38.930
Okay.

04:38.970 --> 04:42.330
And I worked with Jason in the previous videos.

04:42.330 --> 04:50.770
So if you have any question, you can, uh, you can ask it in the comments below, or you can go to

04:50.810 --> 04:54.490
the previous videos and see the JSON converter.

04:54.650 --> 04:56.410
But it's very simple.

04:56.410 --> 05:01.530
It's used for serializing and deserializing objects in Kotlin.

05:01.690 --> 05:08.210
Then we need to add the API interface, the data classes, and the retrofit instance.

05:08.210 --> 05:14.930
As I said before, if you go back to the retrofit section and when implementing retrofit with Android,

05:14.970 --> 05:16.570
we have three steps.

05:16.730 --> 05:25.650
Creating the interface which is the API interface, the data class, and the retrofit instance.

05:25.650 --> 05:28.970
This is what we're going to do in the next video.
