Welcome back and this video, we are going to add a marker to the location where we actually have our
happy place, so we will add a marker on this map.
And you can see here view a map is the button that we need to click in order to get to the screen.
And the beauty is we already give the information about the happy place and the intent.
So we put extra information to the intent in the last video.
And now we can take that data or retrieve the data and then use it.
So let's just do that.
Let's go over to our map activity.
And here I need a new variable which will store that new happy place model object that was given to
us.
So let's create this happy place.
Detail is going to be a happy place model.
Nullable, so I'm just going to assign to it because we will assign something to it once we retrieve
the data.
And where do we get the data from?
Well, we get it from this other activity, right.
So from this heavy place, detailed activity, as you can see here, once we click on this button,
we have this put extra, which is actually a happy place detail model.
And that is our.
Object here, so it's a happy place model object, so the same type, right?
Just a different name.
But then what we need to do is, of course, to get that info from the intent so we can just go ahead
and say, does the intent have extra information about something called main activity dot extra?
And here.
It didn't take the whole activity, so has extra for extra details.
OK, so does it have something like that?
If it does, then let's use it, so let's assign it to our nullable that we created up here.
So I'm happy place details so we can just go ahead and maybe call details so plural and then we can
go ahead and say, I intend to get serializable, extra data and serializable.
Well, in our case, actually, it is get.
Polysyllables extradite him.
So this really depends on how you set it up in your model class.
So in our model happy place model here, I used Pasodoble, but if you used in the serializable way,
then you would, of course, use.
Get serializable extra, but I'm using get Pozible extra and what type of extra is it?
Well, its main activity, that extra place details type of stuff and now we need to.
Cast it into a happy place model.
OK, so we converted here, let's have a look at this again here and a slightly better way so I can
read it better, I'd say.
So we check.
Do we have extra information in the intended was sending us or that sent us over here to this activity,
if that's the case and it actually has this particular name, which is this name here, extra place
details.
Then assign that possible extra information as a happy place model into that happy place details variable
that were created up there.
And now we can check is it empty?
So do we get some information or not?
So I'm happy place details not equal.
Now, if that's the case, then I want to set Support Action Bar, which is our tool bar on a score
map.
And then.
Support Action Bar.
Said display home as an able to true, so then I'll have a back button and here, by the way, toolbar.
Needs to be imported.
All right.
And then the next thing is that I also want to assign the title.
So you might have recognized or realized that there is nothing here.
So no text here.
And that's because we didn't set it up in our map activity.
So let's do that right here.
We assign a title to be a happy place, details which is available.
So we need to use double exclamation mark here and its title.
All right, so here we assign the title and then we need to give the back button a functionality so
we can just go ahead and say to bar map dot set navigation onto Glazner and Percha to do well, basically
just use back press.
So same functionality.
OK, this is nothing new so far.
Right.
Except for maybe this part, but even that we've done already.
So now comes the new stuff, and that is to use a support map fragment.
So let's create a support map fragment object which would be of type of support fragment.
And now.
I'm going to sign here, support fragment manager, not find fragment by IDX.
And now you might recall when we used a fragment that was in our activity map, so here our map here
was a fragment.
So I'm trying to retrieve this fragment here.
So let's do that.
Let's get it by Idy, our dot dot map.
That's the name of it, right, and I need to cast that into a support map fragment because so far it's
just a fragment, right.
But to be more precise, it's actually a supporting fragment.
That's what we have, this class war.
So that's why I signed class here before.
All right, and then.
We can go ahead and support map fragment that get map asynchronously, so it should run in the background
and which maps should it be?
Well, I say it's this.
Why does it complain?
Well, because my class my activity does not yet comply with the.
Unmap, ready, Kobuk.
So let's add on map ready callback, so we're extending this unmap already callback interface, which
is just a public interface, you see, and it has this one function which is called on map ready.
And we need to follow that.
So let's implement those members.
Let's add this on map.
Ready?
And as go all the way down here, you can see now we can define whatever should happen once the map
is ready and it's going to be a Google map.
And as I said earlier, what we want to display here is actually the marker.
So if you want to display a marker, what you need to know is the location.
Right.
And the location of the position that we want to use is going to be the following.
So position will be a let along.
Object, so it needs to be of this type latitude, longitude, and where do we get the latitude from
and where the longitude from?
Well, we get it from our AM Happy Place details, which has our eye wall, which comes from the extra.
Right.
So we get it and get this whole object sent, this happy place model object, which, by the way, has
latitude and longitude here.
And then we use it so we can just say I'm happy, place details that latitude and then am happy place
details dot.
Longitude.
Now, at this point, I'm really forcing it with double exclamation marks, so it could happen that
our happy place teeters is empty, so you could make it even safer here with additional conditions and
everything.
But I'm quite optimistic that the information will be sent because we created the code this way.
Right.
So we send over a happy place model object, and that would work quite right.
So the next thing is that I want to assign a marker on the Google map so it says Unmap ready.
What should happen with this Google map that I'm giving you?
Well, it passes me this Google map and I will use it.
So I'm just going to say Google map, dot add marker.
So at this point, I'm just adding a marker.
And here it's actually called P zero.
So I don't like this name.
P0 is not very descriptive descriptive.
So I'm just going to use Google map and marker and here I'm going to force it and then end marker needs
to have details.
So what kind of details does it need?
Well, it needs marker options.
All right.
So let's give it some marker options that say marker options and let's just look what marker options
there are.
So Alpha snippet rotation, a bunch of different options.
But I just want to give it to position for now and what position, well, you see, need to let long
object.
Guess what?
We have this position which is of table at long.
OK, so we could just pass in our position that we created.
And then we can give it a title.
And which title should be displayed there?
Well, of course, we could use the title of the location or the title of the happy place.
But at the same time, I think having the name of it would be better.
So I'm just going to say it, use the title or assign a title and it should be a string here.
So I'm going to use m happy place details.
Location.
So now I'm taking the location from our happy place model, which is of type string nullable, as you
can see here, and it's the actual location name and not so much the title of the location.
So you could use either way, whatever you prefer.
If you want to display the title of the location, of course you can do that.
But on the other hand, the title is already up here, so it will be in the action bar.
So I don't think it is really necessary at that point.
All right.
And then.
It would be nice to not just have this marker on the screen, because if we test that, we should already
see the marker on the screen, but I would like to have the map zoomed in to that marker so that it
makes sense because otherwise a marker on the world.
Well, it could be something that you maybe want.
So it really depends on what you prefer in terms of the settings.
But now let's just see.
Let's create a new location, because I think so far we didn't create good locations, so I'm going
to call this one Mount Everest and highest mountain on Earth and then let's decide the location.
Mount.
Have a rest.
And I'm just going to use this one here.
I hope it's the right one.
Let's add an image.
I'm going to select one from the gallery and I have one prepared here already.
So I downloaded this image and now let's save it.
And now let's check Mount Everest out.
So view on map.
And there you are.
So it shows me, OK, this is where it is, but at the same time, well, of course I can try to zoom
in, but I am pressing the control key in order to zoom in or keeping it held or pushed, and then you
can swipe around and drag around and everything.
It's a little difficult to use properly.
So it should be somewhere north of India, but, yeah, you see, this is not and behavior that you
would like to have for your application.
So it would really make sense to automatically zoom in to their spot, because right now we can see
where it is when we look at the Earth.
OK, so up here just had Nepal.
And.
Instead, we can, of course, zoom in.
So how do we zoom in?
Well, let's do that new, let alone zoom.
So I'm going to call it, which will be a camera update factory.
New that long zoom.
OK.
And you need to pass in to information.
So let's look at it, the lat long value and then another float, which is the zoom value, and I think
there are something like 15 home values or something like that.
So multiple different zoom levels and you can play around with that.
You could even add a functionality for the user if you want to.
But I'm just going to assign the position as a lifelong value and then I'm going to zoom in with the
15 F value.
So it expects a float value.
So I'm going to give it a float value of 15.
And then there's one last thing to do, and that is to animate our Google map to go to this location.
So this is a pretty cool feature.
It looks great.
So let's use it.
Google map, animated camera.
And here I'm going to use this function here and I'm going to pass a new lat long zoom.
All right, so let's see what this returns.
You can see it returns a camera update, and that's exactly what any camera expects.
So you can see it expects a camera update object.
So that works perfectly together.
So that's why we can use it this way.
And now this will be called, by the way, it is on map ready once the map is ready.
Of course.
All right.
So as soon as our map is completely loaded, then this code here will be executed.
And at that point, we will then zoom in to this location, which I have selected there, which is the
Mt. Everest.
So let's not test this again.
Let's go over to our Mount Everest, let's view this on the map.
And let's see how it zooms and so maps ready and you can see it zooms in all the way.
All right.
So now you can, of course, zoom out and you can see this is the Mount Everest.
And it's just at the border of Nepal and China.
All right, so there we are.
That is pretty cool, feature 15 maybe is too much.
Maybe you just want to use something like, I don't know, 10.
Let's just see the difference.
So this is the value that you can play around with just to see how deep it will zoom in.
Or how far will zoomIn?
So let's select Mount Everest, view this on the map.
And you can see it zoomed in not as far as before, 15 was, of course, a super far zoomed in the screen
here, but I think 10 is a little better for these kind of locations.
But it really depends on the location.
And if someone only has values or only has happy places which are very close by, then I better zoom
would make more sense.
Probably.
All right.
So that is it.
Now you can see how you can use this functionality.
Of course, we are still not using any location specific data, so we're not using the location of the
user.
And that's also something that we will implement later on.
All right.
So see you in the next video.