Welcome back.
In this video we're going to learn how to fetch and display the current location in Google Maps.
We need to start adding the dependencies so Build.gradle file add the location service dependency.
Start with implementation com dot Google dot Android dot g Google Maps services and we need to add the
services location and specify the latest version of location which is 21.3 sync now.
And here we go.
The second thing we need to add is the permissions and the integration of Jetpack Compose with the activity
lifecycle.
Start with implementation activity compose.
So this dependency integrate Jetpack Compose with the activity lifecycle okay sync.
Now we need to use it in order to request permissions at runtime from the user.
So Android X activity.
The library provides backward compatibility.
Versions of Android's core activity components like component activity activity, compose a special
artifact from Android activity that enables using Jetpack Compose UI elements inside Android activity
classes.
It contains utilities to bridge the traditional activity lifecycle with compose.
Okay, so this is the integration.
Without it, uh, and without this dependency, you can't use set content in an activity.
Um, and also you can't request things and permissions and during runtime using the activity lifecycle.
So open the main activity.
The first thing we need to add is the variable for the current location.
So outside the box and the map Google map scope.
Create a variable for the current location var y location by.
Remember and also similar to what we've done before.
Mutable state of.
Start with a location and make sure you add the correct dependency, which is the Android dot location.
Okay, start with initialize null.
And here we go.
This is our location.
This is our variable, my location, which is a state variable that holds an instance of location class
or null.
Initially it's used to store the current location current geographic location of the device.
Okay, this is very important.
We introduced a new type of variables which is the location.
And by using Jetpack Compose to remember the state across our compositions, this means the value survives
the composition.
Composing the composable function.
As long as the composable is still in memory, this is our first step.
In the next video, we're gonna learn how to request the location permission at the runtime.