WEBVTT

00:00.080 --> 00:01.040
Welcome back.

00:01.080 --> 00:09.000
Let's use the location callback and fuse location client in order to create and execute a location request

00:09.040 --> 00:12.200
using Android's Fused Location Provider API.

00:12.360 --> 00:14.240
Go back to Location Repository.

00:14.240 --> 00:20.960
We have start and stop location updates function and let's implement those functions here.

00:21.160 --> 00:31.680
Function override, function start location updates and this location updates function starts with val

00:31.720 --> 00:38.240
location request equals to location request dot builder.

00:38.360 --> 00:48.400
Here we need to specify the priority high accuracy and interval which is 10,000 milliseconds.

00:48.600 --> 00:53.160
Alt plus enter to import priority and dot apply.

00:53.200 --> 00:53.640
Don't worry.

00:53.680 --> 00:56.920
We're gonna we're gonna lecture everything.

00:57.120 --> 01:08.780
And here the interval set it to 5000 and use the build function in this code we are creating the location

01:08.820 --> 01:09.780
request.

01:09.820 --> 01:16.220
This is the location request class dot builder I'm using the builder and passing two parameters.

01:16.260 --> 01:18.900
Priority high accuracy requests.

01:19.020 --> 01:23.460
The most precise location possible typically uses GPS.

01:23.860 --> 01:31.740
Alternatively, we can use passive low power balanced power accuracy, but I prefer using high power.

01:31.980 --> 01:36.980
So high power you the most precise location possible.

01:37.020 --> 01:45.180
10,000 refers for 10s the desired interval between active location updates in milliseconds.

01:45.340 --> 01:50.100
This set minimum update distance meters is not in meters.

01:50.100 --> 01:59.500
We need to set minimum updates in milliliters, which is five seconds, the fastest interval.

01:59.660 --> 02:03.100
The app can handle updates, which is five seconds.

02:03.220 --> 02:09.780
This will prevent two frequent updates when other apps request locations.

02:09.900 --> 02:14.990
Okay, so the location request, the configuration we just built.

02:15.030 --> 02:22.630
Location callback your custom location callback instance that handles incoming locations.

02:22.670 --> 02:26.950
Typically it updates on a state flow or live data for UI.

02:27.150 --> 02:32.990
And this is the logic behind this location repository implementation.

02:32.990 --> 02:36.350
Now we need to continue with this function.

02:36.630 --> 02:44.150
Let's use the try fused location client dot request location updates.

02:44.430 --> 02:47.790
And here we need to set three parameters.

02:47.950 --> 02:52.750
The location request, the executor and location listener.

02:53.070 --> 02:57.030
The first one is the location request we just created.

02:57.070 --> 03:02.150
The second one is the location callback and the third one not null.

03:02.190 --> 03:05.710
We need to use looper dot get main loop.

03:05.750 --> 03:07.470
Then we used catch.

03:07.590 --> 03:16.250
Here set the Logcat tag for example permission exception and print e dot message Okay.

03:16.490 --> 03:17.490
Remove this.

03:17.530 --> 03:18.730
We have an error.

03:19.090 --> 03:19.810
Alt+.

03:19.810 --> 03:20.410
Enter.

03:20.450 --> 03:23.450
Add the requires permission.

03:23.450 --> 03:30.690
Any of manifest file location or manifest dot permission access course location.

03:30.690 --> 03:37.090
Then we need to implement the third or the fourth function which is stop location updates.

03:37.090 --> 03:47.010
It's very simple fused location client dot remove location updates and pass the location callback okay

03:47.250 --> 03:52.130
so this is our location repository implementation.

03:52.130 --> 04:01.490
We have two variables the the user location and has location permission inherited from location repository.

04:01.530 --> 04:09.130
We have to to uh variables fused location client and location callback that are created inside this

04:09.130 --> 04:09.850
class.

04:10.090 --> 04:16.530
And we may use of them in the start location updates and stop location updates.
