Welcome back.
We created the fetch current location function.
Now let's move up in order to pass those two parameters and call this function here.
Inside the is granted, we need to pass two parameters for the fetch current location.
Pass the context object and on location fetched callback.
This is the location which is the the parameter of the lambda expression.
And here what we need to do on the location fetched.
We need to update my location variable to the newly created location or the newly fetched location.
Okay, so here I am updating my location variable to the recently and and current location fetched.
Then we need to request the permission when composable is first launched.
So launched effect unit location permission launcher dot launch and Android manifest permission access
file location.
Go to Android Manifest here.
Please pay attention.
You need to use the access course location and access file location.
Add those permissions in order to get the latest and the current location.
Then we can enable in Google Maps my location button enabled equals to true in order in the map UI settings
in order to get the current location button enabled.
Now, if we get the current location, what we need to do inside the scope of the Google map, here
we can create a marker, a circle, anything around the location.
So here fetching current location.
My location dot let current location val.
We need to get the lat long so we are getting the and transforming.
Transforming a location object into lat long object.
So here we can get the latitude and longitude and store them inside the newly created current location.
Lat long current location dot latitude and current location dot longitude.
Okay, I'm transforming the location.
It's of type location to lat long and store it inside current location.
Okay, now let me add a marker at current location marker marker set the state position equals to current
lat long.
Set the title, current location and a snippet.
You are here.
Let me add the.
For example a shape circle around the location.
Add a circle around the location Circle.
Center left current.
Left long radius.
For example 200m.
Fill color.
Let's make it blue and make it 20% visible.
Stroke color.
Make it white.
Okay, let me run our application.
Did you notice that a request permission launcher allow maps app to access this device location while
using the app?
So here we allow the user and we allow the app to use the permissions and the device permissions.
Okay.
Let me check the current location.
And here is the marker that we created.
Um you can notice this is the current location.
If I zoom in, you notice the circle that I drew on 200m.
And this is our current location.
You can customize the current location by clicking on this three dots extended controls.
Then go to location.
And here you can get the current axis and the and the current position.
So let me make it um in in Europe or in Brazil.
So let me check put the current location in Brazil.
It's good.
So set the location.
We are in Brazil now.
If I run the application again, we get a location.
Maybe we need to wipe the data from device manager.
Wipe data.
So, uh, you can get and change the current location.
Also, um, you can display things around the current location, like, as, uh, we make here by creating
a circle and around the current location.
Okay, so this is how we can get the current location using Google Maps services.