Welcome back.
In this video we're going to learn how to request location permission from the user.
So this is a very important step that is critical for location updates.
Open this package.
Create a new package.
Name it as location.
Inside this location, create a new Kotlin file and name it as location permission handler.
Inside this class, I'm going to create a new composable function.
Name it as request location permission.
That takes two parameters the map view model and on permission granted, which is the lambda expression.
Start with val.
Location permissions equals to remember multiple permission state and inside it create permissions.
List of file location and access course location Alt+.
Enter to import the manifest from Android and Alt+.
Enter to import the function.
And here we go.
This code creates a state holder that manages multiple runtime permissions specifically for location
access.
Both fine and coarse tracks permission status reactively and handles permission requests.
A compose utility, which is remember multiple permission state function that remembers permission state
across Recompositions.
Providing current permission status methods to launch permission requests and automatic recomposition
when permissions change access.
A fine location GPS level accuracy 5 to 50m required for precise location tracking and coarse location.
Network based accuracy from 100 to 500m.
Less precise, but more battery friendly.
So this is for more accurate location.
And this is for low or network based accuracy, or less precise than more than the fine location and
more battery friendly.
Okay, the location permission object provides these important members, so all permissions granted
permissions and launch multiple permission requests.
That triggers system permission dialog.
So for this, create a launched effect location permissions dot.
All permissions are granted.
If all permissions are granted, then go and check if location permissions dot all permissions granted.
What we need to do we need to call ViewModel has location permission dot value.
Set it to true to true and on permission granted.
Otherwise what we need to do, we need to request permissions if not granted.
So location permissions dot launch multiple permission request.
Okay.
So this will be executed once.
So if the location is granted go and set the has location permission that value variable to true and
execute all permission granted.
Otherwise go and create and launch multiple permission requests.