So because you want to access the user's location you need to create value but of type fuse location
provide that API.
So what is this class.
Let's go to the Android documentation.
Any in here just enter this you are a developer that and dot com slash index that.
TMF OK.
So inside the search bar just typing here fused location provided API so it can actually give us this
link.
It says in Google said it's true.
So just click on it.
Let's wait a little bit here.
So it's going up.
Open this page for us to fuse location provide that API.
So it says public interface views like kitchen pro-white API.
So this is actually an interface right.
The main entry point for interacting with diffused the location pro-white there.
So we must have access to these actually use the location provide that API in order to access the user's
location.
Okay this is actually the main entry point.
This is very important.
The method must be used in conjunction with the Google API client so you can see this here it is familiar
to you you already use this piece of code inside are actually the uncreate method in order to initialize
our Google API client instance right.
So you can see this here and now you can see it is constancy a key location change the key marked location.
And let's actually look at these methods.
For example this one pending glissade it says flushers any location is currently being patched and sends
them to all registers and we have the location update it says returns the best most recent location.
Currently available look at this if it here gets last location so we are going to use this method in
order to access that user's location we have location availability here.
So it is actually called returns the availability of location data right.
And all these if it's.
Right.
And we can see that can actually give us some descriptions about these methods.
So this is them for that we are going to use GET last location insets returns the best most recent location
currently available.
If a location is not available which should happen very rarely null will be returned.
Okay the best accuracy available while respecting the location permissions will be returned.
This provides a simplified way to get location.
It is particularly well suited for applications that do not require an accurate location and that do
not actually want to maintain extra logic for allocation updates updates.
So that's enough.
Let's actually go to our Android studio and inside the curly braces of this statement I can actually
create a value of idea but of type fuse location provide that API and the name is going to be just the
fuse location provide that API and puts an assignment operator here.
So because the fuse location pro-white that API is an interface.
This means that we cannot create an object by using the new keyboard.
OK.
So just typing here.
Location services that fused.
So I just need to put a capital F that fuse location API semi-colon.
So now its going actually to give us the fuse location API.
So now this variable holds that right the main entry port in order to actually access the user's location.
So let me actually create a new line here so that you can see this value better.
So now it's time to initialize our location rowdier but that we declared inside our main activity class.
So let me scroll to the top.
You can see this variable here location and we have not yet initialized this location very well so now
it's time to do that.
Let's actually scroll down here and let's go inside this show they use their location method after this
line of code that actually gets the fuse the location API.
I can just type in a location assignment operator and now I can get you to access I can refer to this
fuse location provider IP or so just type in your fuse the location provider API and now we can call
this method and this instance gets last location.
Right.
And as the argument we must pass the Google API client instance.
So we already have that in a sense right.
So just typing here Google API client instance semi-colon.
So you know that we actually created this value but here in line number 23 inside our main activity
class and the initialized this rally about here.
So now we are we need to pass this value here.
This will be the client here as the argument to the Smurfit So now it can actually give us the location
if it is actually not null.
So we need to actually check for that condition.
So here it is called defensive programming.
We must check for any conditions.
Conditions may actually go wrong.
OK the user may not be able to access the location.
We must check for that condition.
So I cant just create an if statement here I can say if location is not equal to non-HD OK that I open
and close this if statement by using curly braces and open incredible is followed by a closing curly
brace inside this statement.
Now I am a hundred and fifty percent sure that this location here is not actually not because I am inside
the curly braces of this statement right.
So here I can say double here and the name of this variable is going to be letter.
So I am actually creating a local variable of type double here latitudes assignment operator.
And now because I have the location here this location actually holds the latitude and longitude coordinates.
So here I can say location that latitude that gets latitude Senechal right and now I can say double
longitude.
Assignment operator location that gets longitude semicolon right.
And now I can actually just type in here TXI the location that said text and insight Apprentice's here.
I can just type in here.
Actually latitude plus two coats and just put a comma here.
Space plus longitude.
So I want to actually outputs the latitude and longitude of the use user's location to the actually
screen.
OK so because we want to access the user's location it is necessary that you run your application on
your actual Android device because the emulator does not have the capability to actually understand
the user's location right.
So here first let's also create an else statement for this if statement here.
So here we are thinking that if the location is not equal to.
All right.
So what happens if the location is actually not in that case we can actually create an else statement
and let the user know that the application.
Would that be able.
We would not be able to access the location now.
So here I can say to the location that said text and instead of prentices I can say the app the app
is not actually able to access the location the location.
Now try again later try again later.
So let me create a new line here so as you can see the idea I put this plus operator here is a concatenation
operator in order to concatenate this value with this value.
When I tried to actually create a new light.
You're right.
So that's it.
So we need to actually also create some efforts it's we need to actually call the Smurfette from another
location from other methods.
So we just created this custom effect here and we are not calling it from other methods yet.
So let's see how we can do that.