Welcome back.
Let's use the location callback and fuse location client in order to create and execute a location request
using Android's Fused Location Provider API.
Go back to Location Repository.
We have start and stop location updates function and let's implement those functions here.
Function override, function start location updates and this location updates function starts with val
location request equals to location request dot builder.
Here we need to specify the priority high accuracy and interval which is 10,000 milliseconds.
Alt plus enter to import priority and dot apply.
Don't worry.
We're gonna we're gonna lecture everything.
And here the interval set it to 5000 and use the build function in this code we are creating the location
request.
This is the location request class dot builder I'm using the builder and passing two parameters.
Priority high accuracy requests.
The most precise location possible typically uses GPS.
Alternatively, we can use passive low power balanced power accuracy, but I prefer using high power.
So high power you the most precise location possible.
10,000 refers for 10s the desired interval between active location updates in milliseconds.
This set minimum update distance meters is not in meters.
We need to set minimum updates in milliliters, which is five seconds, the fastest interval.
The app can handle updates, which is five seconds.
This will prevent two frequent updates when other apps request locations.
Okay, so the location request, the configuration we just built.
Location callback your custom location callback instance that handles incoming locations.
Typically it updates on a state flow or live data for UI.
And this is the logic behind this location repository implementation.
Now we need to continue with this function.
Let's use the try fused location client dot request location updates.
And here we need to set three parameters.
The location request, the executor and location listener.
The first one is the location request we just created.
The second one is the location callback and the third one not null.
We need to use looper dot get main loop.
Then we used catch.
Here set the Logcat tag for example permission exception and print e dot message Okay.
Remove this.
We have an error.
Alt+.
Enter.
Add the requires permission.
Any of manifest file location or manifest dot permission access course location.
Then we need to implement the third or the fourth function which is stop location updates.
It's very simple fused location client dot remove location updates and pass the location callback okay
so this is our location repository implementation.
We have two variables the the user location and has location permission inherited from location repository.
We have to to uh variables fused location client and location callback that are created inside this
class.
And we may use of them in the start location updates and stop location updates.