Welcome back.
We finished the geocode address and we talked about the geocoder.
Now let's move up and outside the box that contains the Google map.
Here I'm going to create the variables that we're going to use in our geocoding process for our search
query, which is a variable that holds a string for the search query.
Mutable state of empty string.
VAR location by.
Remember mutable state of null.
Initially null, but it's of type lat long.
Then var address by.
Remember search or tap on map.
I need to add this question mark and correct the location name var coroutine Scoop equals to remember
coroutine scope.
In Kotlin and Jetpack Compose, this coroutine scope equals to remember coroutine scope is used to create
a remember a coroutine scope that is tied to the lifecycle of a composable function.
The coroutine scope defines the lifecycle of coroutines launched inside it.
If the scope is canceled, all its child coroutines are automatically canceled.
Useful for managing background tasks like API calls, animations, or other async operations.
Remember coroutine scope.
This function creates and remembers a coroutine scope tied to the composition lifecycle.
The scope will automatically be canceled when the composable leaves the composition.
Example when the composable is removed from the UI, unlike launched effect, which runs a coroutine
once.
Remember, coroutine scope allows you to launch coroutines in response to UI events like button clicks.
When we need to use it, you need to manually launch coroutines.
You need to use remember coroutine scope in response to other interactions like button clicks.
And in this case, we're going to use it in order to get the in background, uh, the location for the
geocoding.
Okay.
Then inside the Google map scope, scroll down.
And here we need to make a geocoding part.
So geocoding start with location variable.
Let let location Lat long, which is the parameter for the lambda expression marker.
Set the state marker state title equals to the address snippet and set the longitude dot longitude.
Okay, this is the marker.
This code is used to display a marker on a map if a location location lat long and is available.
So here location which is of type lat long is a nullable object.
If we go back to here scroll down to geocoding.
You notice that the location variable is of type mutable state of lat long and the initial state of
it is null.
So here I am checking if location is not null, then a coroutine scope function will be executed using
the let keyword.
So let here the question mark dot let and the lambda expression.
Here is a coroutine scope function that executes the lambda block only if location is not null inside
the block location.
Let long refers to the non-null location value.
Okay, so here if location is not null, execute or execute the loop or the lambda function.
Okay.
Why we use let safely handles null values because we initialized the location as null and location could
be null.
Uh provides a clean way to transform or use the value if it exists.
Then we created a marker, which is a compose map marker.
It takes several parameters the state, making a state the location.
Lat Lon controls the marker's position and visibility.
And here the title, which is the address type.
Typically a string snippet displays additional information as we learned before.
Okay, so this is the part of the location checking the location variable.
The third part is to create the geocoding user interface.
So outside the map scoop scroll down.
Here we have this the and this parentheses the end of the scoop of the map.
And now we can create the user user interface overlay for geocoding.
In the next video we're going to continue with the geocoding user interface.
And it's very simple user interface.
We need to create a text field a button and a text.