In order to solve this error, which is a hilt component issue, we need to create a module because
inside the map view model we provided two parameters and we inject them.
Marker repository and location repository.
In the previous videos we used the Firebase module in order to provide firebase repository and marker
repository.
Now we're going to do in the same way here a new module object named as location module.
And this object provides the location and repository.
Let's start with provides singleton and provide location repository.
It needs application context variable.
And this function returns a location repository instance which is equal to location repository Implementation,
as we said before in the previous videos, provides annotation marks a function as a dependency provider,
Singleton ensures only one instance is created ensured, and this object has two annotations.
The module and installing the module marks this as a hilt module that provides dependencies.
Installing makes, provide or makes provided dependencies live as long as the application, so we had
only one function provide location repository the module structure object location module.
A Kotlin singleton that groups related dependencies contains one or more provides a function, but in
this case we have only one function providing the location permission and location repository The parameter
application context injects the application context avoids memory leaks and location repository interface.
Abstract type.
The implementation returns a concrete location repository implementation passing context as a parameter.
Why this pattern?
Decoupling implementation from usage.
Making testing easier and centralizing dependency creation.
The hilt specific advantages used for or.
The advantages are.
Auto generates dependency injection code at compile time.
Manages component lifecycles automatically reducing boilerplate code compared to manual dependency injection
and the singleton scoop.
Location services typically need app wide access, avoiding recreating expensive resources.
This is the idea behind creating a model.
Let's build our application and run it.
And here we go.
This is our map.
Let me move to here United States and uh, let me.
And the location didn't appear because I set it to San Francisco.
So you can set and change the current location from here.
From the extended controls, go to location.
And here you can set it on the map.
You can set it here.
And for example in Las Vegas save point click okay and click on Set location.
You can notice that Las Vegas is set as our location.
Now we have an error.
We are not uh requiring the permissions.
And here open the manifest uses permission course access find location and uses permission course location.
Okay.
Also you can use access background location.
Let's run our application again and congratulations guys.
Our application is requesting the permissions during the runtime.
Only this time don't allow or while using the app, click.
While using the app, go to here and wait for the location to appear.
If the location didn't appear, you can go to the settings, so click here.
Go to settings search for location use location is enabled.
See all permissions.
Application allowed only one.
Use the Uber clone the location services location accuracy is on.
Okay, the last thing we need to check is the internet permission access, file location, access course
location and also the metadata API key is set it correctly.
Now let's run our application and see the current position.
These are the markers.
And here we go.
This is our current location.
If you need to change it go to this three dots icon.
And you can for example like change it to Brazil.
Set location and wait for the current location to be changed.
And here we go guys.
After maximum 10s it will appear in the new location.
This is due to the location updates and we set the interval to ten milliseconds 10,000 milliseconds.
Okay thank you guys.
This is how we fetch the location updates in Google Maps.