Hi everyone.
So now you're actually inside these mass activity class.
So in this matter activity class we are going to actually declare a variable.
So is this class distopian private.
And at the top of this idea is strange.
And the name of this variable is received received country right.
Semicolon.
So we are going to actually receive or get the country from the main activity class.
Right.
So now let's go to this other uncreate Smurfette here and after these lines of code here I'm going to
actually put some codes here.
But before that let's take a look at these codes here you can see that.
Take a look at this.
This comment here it says obtain the support map fragment and gets notified when the map is ready to
be used.
OK.
So first it's going to actually get the support of a fragment here and it's going to find a fragment
or that ID that map and it's going to actually call this if it gets map a seen it on this map fragment
here.
Right.
So it is going to actually get them support my fragment and it's going to actually get notified when
that map is ready.
So before the map is ready all you want to get the country from the Minuteman activity you want to get
to use the word that value that is actually passed to that intent.
I want to get that value here before the map is ready.
So after this line of code here that colors sits content to view it I can actually put my own logic
here.
Right.
We need to access the intent that is actually used to send the data to this class.
The intent that is used to transition to this class to this activity.
So just in here intent and here know that the intent that is used to transition to this activity is
the main activity.
So I can just say main activity intent main activity intent assignment operator and I can just call
this if it gets into that semicolon.
That's it by just calling to decide if a good intent on an instance of type maps activities or not is
that it is actually the this that's intent OK.
Does that good intent.
So by calling it an instance of type maps activity here we get the original intent that is used to transition
to this activity here and we are assigning to these valuable here main activity intent.
So now it's time to initialize or valuable that be declared in line number to anyone inside these maps
activity class.
So agency received country assignment operator.
So now I can refer to this intent main activity intent that gets strange extra get something extra.
And here I just need to pass the key in order to access the value that is passed to that intent.
OK.
Let's go back to this man with the glass to this maps activity engine here but just passing the key
here.
Are going to pass the value.
So let's go back to my maps activity class and here we know that the key is let's refer to this country
data source class that contradicts the semicolon.
That's it by just referring to this key I can access the value and the value is going to be assigned
to the received country valuable.
And we know that the value is of type string.
This is really important.
So here there is a problem.
What happens if they have value that is passed to this intent to this activity is actually not OK.
So in that case we are going to actually have some problems.
So in order to solve this problem after this line of code let's create an if statement and let's say
if received country is equal to null then let's open and close this if statement by using these curly
braces.
In that case we are going to say that the received country is going to be there.
Let's refer to this country data source class that default country name semi-hollow So the default country
name is going to be assigned to the received country OK if the rest of the country is not.
So now let's go through this on the map Reddam effort here and here you can see that you are accessing
the Iceland by using these latitude and longitude.
You create you're creating multiple options circle options.
So we don't need to use these actually the calls here let's just delete all these codes here except
this initialization of this map variable Google map.
After this line of code now we're going to put some new logic's here.
So here if you are going to use the geocoding capability and what is to according to geocoding is used
to actually convert of value for example Canada or Canada.
You are going to use a digital coding capability in order to access the latitude and longitude of Canada
into the map.
So that is called geocoding.
But for now let's just create some for example valuables in order to hold the default latitude and longitude
if they received country is actually not.
So let's see what you're going to do next here.
Let's create a variable of type double and the name of this variable is country latitude assignment
operator and initially I'm going to assign the default latitude of the default country to this variable.
So if you go to this country data source class you can see that the default country is Canada.
Right.
And here we specified the latitude and longitude of Canada here as the default country latitude and
default country longitude.
So let's go to these maps activity cles.
So here I can defer.
So initially I'm going to initialize this very well and ensure that I'm going to assign the default
latitude the default country that is actually to this rally.
So when I refer to this country that are sort of class that default country latitude semicolon.
Let's create another variable of type double country longitude assignment operator and just refer to
this country data source class country data source as it is with capital C country data source.
Otherwise the autocomplete feature of Andrew sudi isn't going to help us.
So we must use the capital C in order to access the country that source class that default country longitude
semicolon.
So here let's create a variable of type country data source so I can say country data source and the
name is country data source assignment operator.
So let's go to our main activity class and here let me scroll to the top.
You can see that I created a static variable of type country datasource inside this class and inside
the uncreate in fact I initialized this variable by using this hash table by the above right by using
these countries and messages which is a hash table and I passed this hash table valuable to the constructor
of this class so it is going to construct a new instance of type data source class and it's going to
assign to this valuable country data source.
So we already specified by the U.S. and Canada France Brazil United States Japan.
So we can actually use this instance that we created in say this class.
Let's go back to my maps activity.
So first let me show you that it is actually a static variable.
It is a class variable by just referring to the main activity class.
I can direct the access this country data source instance without creating a new instance of the main
activity.
So let's go back to my maps activity class and I can just refer to this main activity main activity
that country data source semicon and that's it.
And now we initialized this roudy table by just accessing the country data source for instance that
we have inside this main activity class.
So here let's actually create a variable of type stream.
So just in here is strange and the name of this valuable it's going to be country message assignment
operator and now I'm going to refer to this country data source country data source that gets the info
of the country get the info of the country.
So here I just need to pass the country in order to get the value or the message or the info of that
country.
So if I go to this main activity class here you can see that V is specified for for example the country
as the key and the message or the info as the value.
So let's go back to country data source class here at the bottom of the file we created.
I'm afraid you're right.
Get the info out of the country and hear this if it accepts an argument of type string.
So here we are returning this value.
You are referring to this hash table value but that gets country.
So if I pass the country the key you're going to get the value right.
Good country.
This means that past that key an access the value of this has been actually valuable.
So let's go back to main maps activity class and here.
When I say get the info of the country here we just need to pass the key which is going to be the country.
So we have already actually a variable that is called received country.
We actually get this value from the main activity and we are passing this as the key to this effort
and it's going to give us the message devalue and we're going to assign that value to this country message.
Right.
So now it's time to start the geocoding process.
So first of all we need to create an instance of type geocoder.
So just step in here geocoder and the name is going to be geocoder assignment operator new geocoder.
Right.
So here we just need to pass the context which is going to be maps activity that this maps activity
that this semicolon.
So first let me tell you that at any point in the accordion process something can go wrong.
OK.
So we must put our logic into the try catch block in order to capture the exceptions that we may have
in their geocoding process so let's just open here to try.
So we have this triple check and after the I think the price of this Troy block I can't say catch on
here.
Let's use the exception.
I e this open and closed this catch by using curly braces.
So not is that this Iowa exception is a subclass of exception and we can use it in order to actually
capture capture the errors and the exceptions that that may occur inside our project.
So let's go inside is Charlie Black here.
So here first we need to access the address of the country as a string value so that we can actually
start geocoding by using that address and we can convert that string value to the latitude and longitude
of that country name.
So first I need to create a value of type strange and the name of this variable is going to be country
address assignment operator.
And here let's referred to two up valuable that we created inside our class called received country.
So not is that this valuable this value is actually received from the main activity by using the speech
recognition framework.
But using the voice intent.
So that's why it is called received country.
So here it is going to be the address we assign it to this valuable country address.
After this line of code let's create a list of country addresses so I can say list at inside the angle
brackets we need to specify the data type of the objects that we're going to have inside this list.
So it is going to be of type address.
So we already have a class called address in Android that location package.
Let me show you the and the documentation first.
So here it is the android documentation inside the search bar.
Let's search for address.
So here you can see and with that location that address let's click on it and here you can see that
it is actually a class that extends the object class and implements the parsable interface.
So take a look at this description it says a class representing an address or a set of strings describing
a location the address format is a simplified version of X..
So don't about these values here for not just take a look at this summit here and this address locale
constructs and and address object object set to the given locale and with all other fields initialized
to not or false.
We have this clear latitude removes any latitude associated with this address.
You can actually take take a look at this or if it's here for example get at me an area get address
line we can get the country name get through us and all these benefits here.
Right.
So don't worry just let's go back to android studio and now that we have this address class here let's
name this valuable as country atlases country addresses assignment operator.
So let's leave first to the still code for instance geocoder that gets from location name here so you
can see that we have two versions of this for it through this movie.
Again we have two versions of this.
The first one accepts through argument and the second version accepts some more arguments for example
and I accept that the name the max resolves the lower left latitude longitude with the upper right attitude
and the upper right longitude.
So if you're going to use the first version that actually only accepts two arguments location name and
the max resorts.
So we know what is the location and the location name is the country atomists just referred to this
instance to this valuable country address.
Come on.
And the message is always going to be 10 semicolon.
So it's going to give us 10 results maximum by using this country address.
So here let's create an if statement so if country addresses country addresses is not equal to null
here.
We need to actually check for this condition here and only in that case we can assign some real values
to these valuable country and country longitude.
So instead this if statement I can refer to this country land latitude country latitude assignment operator
so insight is least we have values of plate address right country addresses.
So we said that we are going to have 10 maximum results.
So let me tell you that the first result is going to be that the actually the precise one the most precise
address that we can get from this list here.
So I can refer to this country address's country addresses.
So in order to access the first value that we have in say the least I need to call this method get and
here I just need to pass the index which is going to be zero that gets latitude.
So here we are calling to get latitude Meffert on the first object that we have in say the least which
is if they address it right you are calling this method on this object that you have inside this list
and it is the first object.
And I told you that the first one the first object that we have in say this this is going to be the
precise spot.
So actually the most precise one not the precise one.
So now let's put a semicolon at the end of our statement and let's refer to our country a lot longitude
variable country longitude.
So here we created this rally about in line number six the inside are on my ready Meffert assignment
operator.
So again let's refer to this country address's list that gets 0 that gets longitude semi-colon.
So now what happens if the country addresses is actually not.
We need to check for that condition too.
So after this if if statement after the end in Kerley price of this statement let's create an else statement
else here.
We are going to say received country is going to be contrie datasource that default constraining semicolon.
So if the country adolescent's is actually not we we don't have any country here we don't have any real
country.
So if you are going to specify the default country that is specified inside this class country at source
as the country that we have here inside is received act received country rowdier.
OK so now we also have this church block so that you know that this cataplexy is created to catch the
exceptions that may occur in a a joke boarding process.
So look at this line of thought here in line number 70.
We are calling this method to get from location name on this geocoder instance.
So it's going to start geocoding he is going to start the recording process.
So some teens at some point can go wrong.
OK.
So in that case you're going to catch that error.
So in this catch block we're going to say received country assignment operator country datasource that
default country name.
So if anything goes wrong in the recording process are going to specify the default country name as
the received country.
Here we are going to assign this value to the rest of the country.
Right.
So now after this catch block and after the ending curly brace of this catch block and before the end
in place of this method of this on my Prady method here let's put some more logic here.
So first let me tell you that now that we actually that we are actually using these data that we are
for example accessing the received received country we are getting the country message here and we are
starting to geocoding process after all these codes and after the geocoding process.
Now it's time to modify the map itself.
So here before the ading curly brace of the Smurfette I can't say.
So let's create of the of type lot land and the name of this variable is going to be my country my country
location assignment operator new law land survey to pass through arguments to the constructor.
First we need to specify the latitude and longitude.
So we created these two variables inside this class right country latitude and country longitude.
So let's pass them here.
Country latitude comma country longitude semi-colon.
And here let's create a variable of type camera update and the name of this variable is camera update
assignment operator Chamula update factory.
That's Neil.
Zoom here.
So so he had a very 2:02 arguments to this method.
First we need to pass an object of type let's land.
And let me show you this method again.
And the second argument is going to be the preciseness I should keep the zooming value that we need
that you want to have.
Is zooming out or this woman out for example if you passed 17 that is going to be the zooming value
that you want to use on this location.
So you are already familiar with that by the way.
So first let's pass the last line Optik is it is going to be my country location comma and the zoomie
radio is going to be seventeen point two.
You can't use whatever value you want but I just I just prefer disvalue seventeen point two.
Let me create a new line so that you can see what's going on here.
So now we need to call this method that's actually fair to our map for instance valuable thoughts move
camera.
And I just need to pass this camera update to the Smurfit.
Right.
And now it's time to create a marker on this location.
So just they've been here monitored options multiple options.
Assignment operator new monitor options semicolon First we need to specify the position of this market
option.
So market options that position.
So the position is going to be of type.
And we know that here.
So we actually already created a variable of type last thing.
So I can pass that here in my country location semi-colon and let's specify the title of this market.
So I can say multiple options that title.
So we already created a value bet that is can be used for the title.
So it is actually the country message here right by referring to the contrary message that we can actually
access the intent that the info or the message of that country.
So let's pass that here the title country message semicolon.
And here we can also specify that snippet.
So just typing here eruptions that snippets.
So let's go to our country data source class here.
If you scroll to the top here you can see that we have this default message here.
So let's change this value to be happy for example.
So let's go back to our map activity here.
And now I can refer to this constant here so I can't say Country data source that default message semicolon.
Now let's refer to a map instance valuable.
That's at marker.
So we have these small options here semicolon.
So it's going to actually add this much to our map.
So finally let's create a value of type circle options circle options circle options assignment operator
new circle options semicolon.
Say circle options that center.
So we need to pass a value of type last line and it is going to be my country location semicolon and
now we need to specify the radius.
So I can say circle options that radius.
So now I can say a 400 semicolon circle options thought stroke with stroke which I can pass a value
of that float.
Fourteen point five if semi-colon.
And finally let's specify that scroll through each color circle options.
That's true color color.
Dots here.
I can actually use on any nice semi-colon.
And finally let's add let's add this sort of co-option to our map so map that at circle circle options
certain call that's it.
So I think now it's time to run the application.
So let's run it and let's see what happens.
Let me show you the emulator.
So here you can see that our application is running on the simulator.
But again the emulator does not fully support the speech recognition framework so you need to actually
test this app on your actual device.
So I'm going to take this up on my actual device and I'm going to record my screen device and then I'm
going to show you what's going on here.
So I tested the app on my android actual device and here first let me tell you that make sure that you
have an Internet connection on your device.
And as you can see my wife is actually turned on here.
So let's let me actually play the video and then let me show you how it went.
Let's play.
So here I said Japan and here it actually opened the map activity so I zoomed out a little bit in order
to show you this marker here.
And you can see this little circle and if I actually zoom out in order to show you the Japan country
here and here if I zoom in again now you can see this molecule option.
This little circle and now I'm going to actually touch this mulcher and it says Welcome to Japan happy
visiting be happy.
Right.
So that's it.
OK everyone AB 79 is now finished.
If you want to you can actually add more functionality to this application and you can actually make
up your own and upload it to the Google Play store and in fact I recommend you to do that and make sure
to actually share the link of your application in Google Play store with other students and beat me
so that we can actually just give you some suggestions in order to make it better.
So thank you very much for watching.
The next app is going to be an e-commerce app so I'll see you in the next tutorial.