WEBVTT

00:00.120 --> 00:07.800
In order to solve this error, which is a hilt component issue, we need to create a module because

00:08.040 --> 00:13.840
inside the map view model we provided two parameters and we inject them.

00:13.880 --> 00:16.560
Marker repository and location repository.

00:16.560 --> 00:23.720
In the previous videos we used the Firebase module in order to provide firebase repository and marker

00:23.720 --> 00:24.600
repository.

00:24.840 --> 00:34.120
Now we're going to do in the same way here a new module object named as location module.

00:34.400 --> 00:40.840
And this object provides the location and repository.

00:40.880 --> 00:47.640
Let's start with provides singleton and provide location repository.

00:47.800 --> 00:51.400
It needs application context variable.

00:51.400 --> 01:01.110
And this function returns a location repository instance which is equal to location repository Implementation,

01:01.110 --> 01:08.590
as we said before in the previous videos, provides annotation marks a function as a dependency provider,

01:08.590 --> 01:17.750
Singleton ensures only one instance is created ensured, and this object has two annotations.

01:17.750 --> 01:26.750
The module and installing the module marks this as a hilt module that provides dependencies.

01:26.750 --> 01:37.150
Installing makes, provide or makes provided dependencies live as long as the application, so we had

01:37.270 --> 01:44.750
only one function provide location repository the module structure object location module.

01:44.790 --> 01:53.350
A Kotlin singleton that groups related dependencies contains one or more provides a function, but in

01:53.350 --> 02:00.990
this case we have only one function providing the location permission and location repository The parameter

02:00.990 --> 02:09.510
application context injects the application context avoids memory leaks and location repository interface.

02:09.550 --> 02:10.750
Abstract type.

02:10.950 --> 02:19.310
The implementation returns a concrete location repository implementation passing context as a parameter.

02:19.430 --> 02:21.030
Why this pattern?

02:21.070 --> 02:24.430
Decoupling implementation from usage.

02:24.590 --> 02:30.110
Making testing easier and centralizing dependency creation.

02:30.150 --> 02:33.750
The hilt specific advantages used for or.

02:34.230 --> 02:35.590
The advantages are.

02:35.630 --> 02:40.030
Auto generates dependency injection code at compile time.

02:40.230 --> 02:49.510
Manages component lifecycles automatically reducing boilerplate code compared to manual dependency injection

02:49.510 --> 02:51.070
and the singleton scoop.

02:51.110 --> 02:59.390
Location services typically need app wide access, avoiding recreating expensive resources.

02:59.420 --> 03:02.220
This is the idea behind creating a model.

03:02.380 --> 03:06.940
Let's build our application and run it.

03:06.940 --> 03:07.780
And here we go.

03:07.820 --> 03:09.020
This is our map.

03:09.180 --> 03:14.100
Let me move to here United States and uh, let me.

03:14.140 --> 03:20.500
And the location didn't appear because I set it to San Francisco.

03:20.500 --> 03:24.260
So you can set and change the current location from here.

03:24.380 --> 03:28.020
From the extended controls, go to location.

03:28.020 --> 03:31.580
And here you can set it on the map.

03:31.580 --> 03:33.140
You can set it here.

03:33.380 --> 03:42.460
And for example in Las Vegas save point click okay and click on Set location.

03:42.460 --> 03:46.700
You can notice that Las Vegas is set as our location.

03:46.740 --> 03:48.900
Now we have an error.

03:48.940 --> 03:52.220
We are not uh requiring the permissions.

03:52.220 --> 04:03.690
And here open the manifest uses permission course access find location and uses permission course location.

04:03.730 --> 04:04.330
Okay.

04:04.370 --> 04:07.290
Also you can use access background location.

04:07.410 --> 04:11.450
Let's run our application again and congratulations guys.

04:11.730 --> 04:16.730
Our application is requesting the permissions during the runtime.

04:16.730 --> 04:20.370
Only this time don't allow or while using the app, click.

04:20.370 --> 04:25.770
While using the app, go to here and wait for the location to appear.

04:25.890 --> 04:31.410
If the location didn't appear, you can go to the settings, so click here.

04:31.530 --> 04:37.650
Go to settings search for location use location is enabled.

04:37.650 --> 04:39.770
See all permissions.

04:39.810 --> 04:43.090
Application allowed only one.

04:43.130 --> 04:50.410
Use the Uber clone the location services location accuracy is on.

04:50.570 --> 04:57.490
Okay, the last thing we need to check is the internet permission access, file location, access course

04:57.530 --> 05:02.610
location and also the metadata API key is set it correctly.

05:02.730 --> 05:07.690
Now let's run our application and see the current position.

05:07.730 --> 05:09.250
These are the markers.

05:09.370 --> 05:11.210
And here we go.

05:11.250 --> 05:13.890
This is our current location.

05:13.890 --> 05:20.010
If you need to change it go to this three dots icon.

05:20.010 --> 05:24.850
And you can for example like change it to Brazil.

05:25.170 --> 05:30.090
Set location and wait for the current location to be changed.

05:30.130 --> 05:31.490
And here we go guys.

05:31.490 --> 05:36.330
After maximum 10s it will appear in the new location.

05:36.530 --> 05:45.930
This is due to the location updates and we set the interval to ten milliseconds 10,000 milliseconds.

05:46.170 --> 05:47.810
Okay thank you guys.

05:48.010 --> 05:53.410
This is how we fetch the location updates in Google Maps.
