Hello developers, and welcome back.
Congratulations for building this amazing app and thank you for being patient with me.
I hope you benefit from our courses and rate us five stars on Udemy.
And I promise you, if you support me writing us five stars on Udemy, I'll continue adding more and
more features and more and more videos to this course.
Okay, now let's begin with our lesson.
In this video I'm going to introduce something called directions API.
Go to Google Cloud or Console.cloud.google.com.
Select your project APIs and services, scroll down, search for directions API and choose it.
Scroll down and make sure you enable it here so directions API is enabled.
The Google Maps Directions API is a service that calculates directions between locations, including
various modes of transportation, driving, walking, bicycling, or transit.
So it's a very important feature we're going to add to our application.
Go to the keys.
And I think they are the same key as before.
Click on show key and you'll get the same key API key as we did before.
Okay.
Now go back to our application.
Make sure you added the maps compose and play services maps here.
Scroll down and add the Google Maps services.
And as you remember before we added Play services, maps, compose widgets and util, we can add here
for directions.
Com that Google Android Play Services maps sync now and here we go.
Now I want from you to focus with me.
We need to add retrofit in order to use directions.
API retrofit is not strictly required to use the directions API, but it offers several advantages over
the traditional Google Maps services.
Java client that library used in the first couple of minutes.
So here we're gonna add retrofit library in order to make connections more and more fast and reliable.
Okay, so I'm gonna use retrofit in order to make the HTTP requests and calls.
Being more and more professional, retrofit is a type safe HTTP client for Android, and Java handles
all the low level HTTP work, connection pooling, threading, and etc. built on top of HTTP and native
support for coroutines.
Also, it provides cleaner error handling and more idiomatic Kotlin code.
The official Google Maps services library is quite large, so here the services is quite large.
It's about two megabytes.
Retrofit plus is typically smaller if you're already using them, so you can use this in order to add
the services for maps.
Or you can use retrofit clients.
Okay, so I'll show you the fastest and more professional way which using which is using retrofit.
Go to download copy this implementation and paste it here.
Then add the implementation for the G-Sync converter and you can use the HTTP three logging interceptor.
We need the converter in order to make the serializing and deserializing for the objects, so retrofit
ensures the type safety, coroutine support, apk size, impact customization, error handling, JSON
parsing, and so on.
Okay, the first thing we need to add is retrofit library.
The second thing is the converter JSON.
You can select the other converters, for example, go to converters.
Jason Jackson, mochi and so on.
I preferred Mochi and Jason.
They are most reliable and the most efficient converters.
Okay.
And I worked with Jason in the previous videos.
So if you have any question, you can, uh, you can ask it in the comments below, or you can go to
the previous videos and see the JSON converter.
But it's very simple.
It's used for serializing and deserializing objects in Kotlin.
Then we need to add the API interface, the data classes, and the retrofit instance.
As I said before, if you go back to the retrofit section and when implementing retrofit with Android,
we have three steps.
Creating the interface which is the API interface, the data class, and the retrofit instance.
This is what we're going to do in the next video.