WEBVTT

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

00:01.240 --> 00:08.080
In this video we're going to learn how to fetch and display the current location in Google Maps.

00:08.080 --> 00:18.280
We need to start adding the dependencies so Build.gradle file add the location service dependency.

00:18.440 --> 00:32.320
Start with implementation com dot Google dot Android dot g Google Maps services and we need to add the

00:32.440 --> 00:40.440
services location and specify the latest version of location which is 21.3 sync now.

00:40.440 --> 00:41.440
And here we go.

00:41.480 --> 00:50.200
The second thing we need to add is the permissions and the integration of Jetpack Compose with the activity

00:50.240 --> 00:51.320
lifecycle.

00:51.320 --> 00:55.960
Start with implementation activity compose.

00:56.080 --> 01:03.160
So this dependency integrate Jetpack Compose with the activity lifecycle okay sync.

01:03.160 --> 01:10.000
Now we need to use it in order to request permissions at runtime from the user.

01:10.000 --> 01:12.120
So Android X activity.

01:12.120 --> 01:14.280
The library provides backward compatibility.

01:14.320 --> 01:21.400
Versions of Android's core activity components like component activity activity, compose a special

01:21.440 --> 01:29.760
artifact from Android activity that enables using Jetpack Compose UI elements inside Android activity

01:29.760 --> 01:30.600
classes.

01:30.600 --> 01:36.200
It contains utilities to bridge the traditional activity lifecycle with compose.

01:36.560 --> 01:38.600
Okay, so this is the integration.

01:38.640 --> 01:45.520
Without it, uh, and without this dependency, you can't use set content in an activity.

01:45.760 --> 01:53.800
Um, and also you can't request things and permissions and during runtime using the activity lifecycle.

01:54.120 --> 01:56.160
So open the main activity.

01:56.160 --> 02:03.200
The first thing we need to add is the variable for the current location.

02:03.200 --> 02:08.000
So outside the box and the map Google map scope.

02:08.040 --> 02:15.400
Create a variable for the current location var y location by.

02:15.400 --> 02:19.130
Remember and also similar to what we've done before.

02:19.370 --> 02:21.370
Mutable state of.

02:21.690 --> 02:30.770
Start with a location and make sure you add the correct dependency, which is the Android dot location.

02:30.810 --> 02:33.730
Okay, start with initialize null.

02:33.890 --> 02:35.050
And here we go.

02:35.090 --> 02:37.210
This is our location.

02:37.210 --> 02:45.530
This is our variable, my location, which is a state variable that holds an instance of location class

02:45.770 --> 02:46.490
or null.

02:46.490 --> 02:55.370
Initially it's used to store the current location current geographic location of the device.

02:55.410 --> 02:57.290
Okay, this is very important.

02:57.370 --> 03:01.770
We introduced a new type of variables which is the location.

03:02.170 --> 03:10.490
And by using Jetpack Compose to remember the state across our compositions, this means the value survives

03:10.490 --> 03:11.210
the composition.

03:11.410 --> 03:14.570
Composing the composable function.

03:14.770 --> 03:21.330
As long as the composable is still in memory, this is our first step.

03:21.490 --> 03:27.370
In the next video, we're gonna learn how to request the location permission at the runtime.
