1
00:00:00,420 --> 00:00:06,450
Welcome back and this video, we are going to add a marker to the location where we actually have our

2
00:00:06,450 --> 00:00:10,260
happy place, so we will add a marker on this map.

3
00:00:10,260 --> 00:00:15,510
And you can see here view a map is the button that we need to click in order to get to the screen.

4
00:00:15,510 --> 00:00:22,340
And the beauty is we already give the information about the happy place and the intent.

5
00:00:22,470 --> 00:00:25,860
So we put extra information to the intent in the last video.

6
00:00:25,860 --> 00:00:30,360
And now we can take that data or retrieve the data and then use it.

7
00:00:30,510 --> 00:00:31,460
So let's just do that.

8
00:00:32,070 --> 00:00:34,110
Let's go over to our map activity.

9
00:00:34,320 --> 00:00:41,580
And here I need a new variable which will store that new happy place model object that was given to

10
00:00:41,580 --> 00:00:41,710
us.

11
00:00:41,720 --> 00:00:44,880
So let's create this happy place.

12
00:00:45,120 --> 00:00:49,800
Detail is going to be a happy place model.

13
00:00:50,900 --> 00:00:57,110
Nullable, so I'm just going to assign to it because we will assign something to it once we retrieve

14
00:00:57,110 --> 00:00:57,600
the data.

15
00:00:57,830 --> 00:00:59,690
And where do we get the data from?

16
00:01:00,020 --> 00:01:02,090
Well, we get it from this other activity, right.

17
00:01:02,120 --> 00:01:06,380
So from this heavy place, detailed activity, as you can see here, once we click on this button,

18
00:01:06,710 --> 00:01:11,750
we have this put extra, which is actually a happy place detail model.

19
00:01:12,620 --> 00:01:15,530
And that is our.

20
00:01:18,420 --> 00:01:23,220
Object here, so it's a happy place model object, so the same type, right?

21
00:01:23,500 --> 00:01:24,290
Just a different name.

22
00:01:24,660 --> 00:01:30,990
But then what we need to do is, of course, to get that info from the intent so we can just go ahead

23
00:01:30,990 --> 00:01:38,250
and say, does the intent have extra information about something called main activity dot extra?

24
00:01:39,120 --> 00:01:39,900
And here.

25
00:01:41,690 --> 00:01:47,780
It didn't take the whole activity, so has extra for extra details.

26
00:01:48,760 --> 00:01:50,490
OK, so does it have something like that?

27
00:01:52,160 --> 00:01:57,490
If it does, then let's use it, so let's assign it to our nullable that we created up here.

28
00:01:57,770 --> 00:02:05,510
So I'm happy place details so we can just go ahead and maybe call details so plural and then we can

29
00:02:05,510 --> 00:02:11,290
go ahead and say, I intend to get serializable, extra data and serializable.

30
00:02:11,300 --> 00:02:14,510
Well, in our case, actually, it is get.

31
00:02:16,620 --> 00:02:18,130
Polysyllables extradite him.

32
00:02:18,360 --> 00:02:22,610
So this really depends on how you set it up in your model class.

33
00:02:22,620 --> 00:02:30,780
So in our model happy place model here, I used Pasodoble, but if you used in the serializable way,

34
00:02:30,780 --> 00:02:32,070
then you would, of course, use.

35
00:02:33,090 --> 00:02:39,810
Get serializable extra, but I'm using get Pozible extra and what type of extra is it?

36
00:02:39,840 --> 00:02:48,930
Well, its main activity, that extra place details type of stuff and now we need to.

37
00:02:51,100 --> 00:02:53,010
Cast it into a happy place model.

38
00:02:53,550 --> 00:03:01,570
OK, so we converted here, let's have a look at this again here and a slightly better way so I can

39
00:03:01,570 --> 00:03:03,090
read it better, I'd say.

40
00:03:03,340 --> 00:03:04,000
So we check.

41
00:03:04,000 --> 00:03:11,620
Do we have extra information in the intended was sending us or that sent us over here to this activity,

42
00:03:12,160 --> 00:03:18,810
if that's the case and it actually has this particular name, which is this name here, extra place

43
00:03:18,820 --> 00:03:19,330
details.

44
00:03:21,890 --> 00:03:31,940
Then assign that possible extra information as a happy place model into that happy place details variable

45
00:03:31,950 --> 00:03:33,050
that were created up there.

46
00:03:34,730 --> 00:03:36,900
And now we can check is it empty?

47
00:03:37,610 --> 00:03:39,880
So do we get some information or not?

48
00:03:40,100 --> 00:03:43,480
So I'm happy place details not equal.

49
00:03:43,490 --> 00:03:54,140
Now, if that's the case, then I want to set Support Action Bar, which is our tool bar on a score

50
00:03:54,140 --> 00:03:54,490
map.

51
00:03:55,640 --> 00:03:56,270
And then.

52
00:03:57,380 --> 00:04:00,680
Support Action Bar.

53
00:04:02,500 --> 00:04:09,940
Said display home as an able to true, so then I'll have a back button and here, by the way, toolbar.

54
00:04:12,140 --> 00:04:13,220
Needs to be imported.

55
00:04:13,640 --> 00:04:14,070
All right.

56
00:04:14,690 --> 00:04:18,019
And then the next thing is that I also want to assign the title.

57
00:04:18,029 --> 00:04:22,180
So you might have recognized or realized that there is nothing here.

58
00:04:22,190 --> 00:04:23,170
So no text here.

59
00:04:23,300 --> 00:04:27,020
And that's because we didn't set it up in our map activity.

60
00:04:27,020 --> 00:04:28,130
So let's do that right here.

61
00:04:28,580 --> 00:04:34,570
We assign a title to be a happy place, details which is available.

62
00:04:34,580 --> 00:04:38,000
So we need to use double exclamation mark here and its title.

63
00:04:39,780 --> 00:04:46,860
All right, so here we assign the title and then we need to give the back button a functionality so

64
00:04:46,860 --> 00:04:55,380
we can just go ahead and say to bar map dot set navigation onto Glazner and Percha to do well, basically

65
00:04:55,380 --> 00:04:57,080
just use back press.

66
00:04:57,450 --> 00:04:58,600
So same functionality.

67
00:04:58,950 --> 00:05:00,810
OK, this is nothing new so far.

68
00:05:00,840 --> 00:05:01,230
Right.

69
00:05:01,500 --> 00:05:04,910
Except for maybe this part, but even that we've done already.

70
00:05:05,280 --> 00:05:10,730
So now comes the new stuff, and that is to use a support map fragment.

71
00:05:11,400 --> 00:05:19,500
So let's create a support map fragment object which would be of type of support fragment.

72
00:05:23,710 --> 00:05:24,310
And now.

73
00:05:25,440 --> 00:05:32,250
I'm going to sign here, support fragment manager, not find fragment by IDX.

74
00:05:34,120 --> 00:05:42,610
And now you might recall when we used a fragment that was in our activity map, so here our map here

75
00:05:42,880 --> 00:05:44,150
was a fragment.

76
00:05:44,500 --> 00:05:46,690
So I'm trying to retrieve this fragment here.

77
00:05:47,780 --> 00:05:49,160
So let's do that.

78
00:05:49,340 --> 00:05:53,370
Let's get it by Idy, our dot dot map.

79
00:05:54,620 --> 00:06:02,060
That's the name of it, right, and I need to cast that into a support map fragment because so far it's

80
00:06:02,060 --> 00:06:03,100
just a fragment, right.

81
00:06:03,110 --> 00:06:07,820
But to be more precise, it's actually a supporting fragment.

82
00:06:07,830 --> 00:06:09,370
That's what we have, this class war.

83
00:06:09,650 --> 00:06:11,750
So that's why I signed class here before.

84
00:06:12,770 --> 00:06:13,670
All right, and then.

85
00:06:16,050 --> 00:06:27,450
We can go ahead and support map fragment that get map asynchronously, so it should run in the background

86
00:06:27,660 --> 00:06:29,040
and which maps should it be?

87
00:06:29,370 --> 00:06:30,690
Well, I say it's this.

88
00:06:30,810 --> 00:06:32,220
Why does it complain?

89
00:06:32,610 --> 00:06:39,000
Well, because my class my activity does not yet comply with the.

90
00:06:40,210 --> 00:06:41,630
Unmap, ready, Kobuk.

91
00:06:42,250 --> 00:06:50,860
So let's add on map ready callback, so we're extending this unmap already callback interface, which

92
00:06:50,860 --> 00:06:56,770
is just a public interface, you see, and it has this one function which is called on map ready.

93
00:06:57,310 --> 00:06:59,620
And we need to follow that.

94
00:06:59,630 --> 00:07:01,390
So let's implement those members.

95
00:07:01,990 --> 00:07:03,610
Let's add this on map.

96
00:07:03,610 --> 00:07:04,000
Ready?

97
00:07:05,510 --> 00:07:11,300
And as go all the way down here, you can see now we can define whatever should happen once the map

98
00:07:11,300 --> 00:07:14,170
is ready and it's going to be a Google map.

99
00:07:14,540 --> 00:07:19,790
And as I said earlier, what we want to display here is actually the marker.

100
00:07:20,280 --> 00:07:24,400
So if you want to display a marker, what you need to know is the location.

101
00:07:24,950 --> 00:07:25,160
Right.

102
00:07:25,260 --> 00:07:30,330
And the location of the position that we want to use is going to be the following.

103
00:07:30,350 --> 00:07:34,670
So position will be a let along.

104
00:07:35,800 --> 00:07:41,650
Object, so it needs to be of this type latitude, longitude, and where do we get the latitude from

105
00:07:42,040 --> 00:07:43,510
and where the longitude from?

106
00:07:43,870 --> 00:07:52,750
Well, we get it from our AM Happy Place details, which has our eye wall, which comes from the extra.

107
00:07:52,870 --> 00:07:53,140
Right.

108
00:07:53,150 --> 00:07:59,950
So we get it and get this whole object sent, this happy place model object, which, by the way, has

109
00:08:00,070 --> 00:08:01,600
latitude and longitude here.

110
00:08:02,500 --> 00:08:14,770
And then we use it so we can just say I'm happy, place details that latitude and then am happy place

111
00:08:14,770 --> 00:08:15,700
details dot.

112
00:08:17,320 --> 00:08:18,140
Longitude.

113
00:08:18,820 --> 00:08:24,670
Now, at this point, I'm really forcing it with double exclamation marks, so it could happen that

114
00:08:24,670 --> 00:08:31,240
our happy place teeters is empty, so you could make it even safer here with additional conditions and

115
00:08:31,240 --> 00:08:31,720
everything.

116
00:08:32,080 --> 00:08:37,330
But I'm quite optimistic that the information will be sent because we created the code this way.

117
00:08:37,330 --> 00:08:37,590
Right.

118
00:08:37,600 --> 00:08:43,690
So we send over a happy place model object, and that would work quite right.

119
00:08:44,230 --> 00:08:51,430
So the next thing is that I want to assign a marker on the Google map so it says Unmap ready.

120
00:08:51,640 --> 00:08:54,730
What should happen with this Google map that I'm giving you?

121
00:08:54,970 --> 00:08:58,980
Well, it passes me this Google map and I will use it.

122
00:08:59,110 --> 00:09:04,930
So I'm just going to say Google map, dot add marker.

123
00:09:05,050 --> 00:09:07,150
So at this point, I'm just adding a marker.

124
00:09:07,510 --> 00:09:12,000
And here it's actually called P zero.

125
00:09:12,010 --> 00:09:13,060
So I don't like this name.

126
00:09:13,540 --> 00:09:17,080
P0 is not very descriptive descriptive.

127
00:09:17,080 --> 00:09:24,340
So I'm just going to use Google map and marker and here I'm going to force it and then end marker needs

128
00:09:24,340 --> 00:09:25,120
to have details.

129
00:09:25,140 --> 00:09:26,680
So what kind of details does it need?

130
00:09:27,280 --> 00:09:29,350
Well, it needs marker options.

131
00:09:29,590 --> 00:09:29,980
All right.

132
00:09:29,980 --> 00:09:36,160
So let's give it some marker options that say marker options and let's just look what marker options

133
00:09:36,160 --> 00:09:36,640
there are.

134
00:09:37,480 --> 00:09:41,500
So Alpha snippet rotation, a bunch of different options.

135
00:09:41,500 --> 00:09:47,140
But I just want to give it to position for now and what position, well, you see, need to let long

136
00:09:47,170 --> 00:09:47,740
object.

137
00:09:47,740 --> 00:09:48,220
Guess what?

138
00:09:48,220 --> 00:09:50,230
We have this position which is of table at long.

139
00:09:50,920 --> 00:09:54,370
OK, so we could just pass in our position that we created.

140
00:09:55,520 --> 00:09:57,950
And then we can give it a title.

141
00:09:58,930 --> 00:10:00,970
And which title should be displayed there?

142
00:10:01,510 --> 00:10:08,200
Well, of course, we could use the title of the location or the title of the happy place.

143
00:10:09,770 --> 00:10:14,250
But at the same time, I think having the name of it would be better.

144
00:10:14,540 --> 00:10:20,510
So I'm just going to say it, use the title or assign a title and it should be a string here.

145
00:10:20,510 --> 00:10:24,470
So I'm going to use m happy place details.

146
00:10:26,660 --> 00:10:27,330
Location.

147
00:10:29,000 --> 00:10:34,730
So now I'm taking the location from our happy place model, which is of type string nullable, as you

148
00:10:34,730 --> 00:10:41,830
can see here, and it's the actual location name and not so much the title of the location.

149
00:10:41,840 --> 00:10:45,080
So you could use either way, whatever you prefer.

150
00:10:45,080 --> 00:10:48,680
If you want to display the title of the location, of course you can do that.

151
00:10:48,680 --> 00:10:55,160
But on the other hand, the title is already up here, so it will be in the action bar.

152
00:10:55,370 --> 00:10:58,430
So I don't think it is really necessary at that point.

153
00:10:59,090 --> 00:10:59,500
All right.

154
00:10:59,510 --> 00:10:59,900
And then.

155
00:11:00,840 --> 00:11:05,760
It would be nice to not just have this marker on the screen, because if we test that, we should already

156
00:11:05,760 --> 00:11:14,250
see the marker on the screen, but I would like to have the map zoomed in to that marker so that it

157
00:11:14,250 --> 00:11:17,340
makes sense because otherwise a marker on the world.

158
00:11:17,520 --> 00:11:20,040
Well, it could be something that you maybe want.

159
00:11:20,340 --> 00:11:23,340
So it really depends on what you prefer in terms of the settings.

160
00:11:23,760 --> 00:11:25,440
But now let's just see.

161
00:11:26,390 --> 00:11:32,240
Let's create a new location, because I think so far we didn't create good locations, so I'm going

162
00:11:32,240 --> 00:11:44,240
to call this one Mount Everest and highest mountain on Earth and then let's decide the location.

163
00:11:46,540 --> 00:11:47,260
Mount.

164
00:11:48,700 --> 00:11:49,540
Have a rest.

165
00:11:52,270 --> 00:11:54,070
And I'm just going to use this one here.

166
00:11:54,430 --> 00:11:55,570
I hope it's the right one.

167
00:11:55,900 --> 00:11:56,920
Let's add an image.

168
00:11:57,190 --> 00:12:00,700
I'm going to select one from the gallery and I have one prepared here already.

169
00:12:01,120 --> 00:12:05,320
So I downloaded this image and now let's save it.

170
00:12:06,610 --> 00:12:08,650
And now let's check Mount Everest out.

171
00:12:08,650 --> 00:12:09,880
So view on map.

172
00:12:12,600 --> 00:12:13,450
And there you are.

173
00:12:13,620 --> 00:12:20,850
So it shows me, OK, this is where it is, but at the same time, well, of course I can try to zoom

174
00:12:20,850 --> 00:12:31,170
in, but I am pressing the control key in order to zoom in or keeping it held or pushed, and then you

175
00:12:31,170 --> 00:12:34,080
can swipe around and drag around and everything.

176
00:12:34,080 --> 00:12:36,560
It's a little difficult to use properly.

177
00:12:38,010 --> 00:12:46,440
So it should be somewhere north of India, but, yeah, you see, this is not and behavior that you

178
00:12:46,440 --> 00:12:47,900
would like to have for your application.

179
00:12:47,910 --> 00:12:52,920
So it would really make sense to automatically zoom in to their spot, because right now we can see

180
00:12:52,920 --> 00:12:54,770
where it is when we look at the Earth.

181
00:12:55,840 --> 00:12:59,290
OK, so up here just had Nepal.

182
00:13:00,490 --> 00:13:01,240
And.

183
00:13:02,310 --> 00:13:03,690
Instead, we can, of course, zoom in.

184
00:13:03,900 --> 00:13:04,860
So how do we zoom in?

185
00:13:04,890 --> 00:13:08,780
Well, let's do that new, let alone zoom.

186
00:13:09,330 --> 00:13:14,760
So I'm going to call it, which will be a camera update factory.

187
00:13:15,570 --> 00:13:17,100
New that long zoom.

188
00:13:18,030 --> 00:13:18,420
OK.

189
00:13:19,950 --> 00:13:22,200
And you need to pass in to information.

190
00:13:22,770 --> 00:13:30,060
So let's look at it, the lat long value and then another float, which is the zoom value, and I think

191
00:13:30,060 --> 00:13:32,890
there are something like 15 home values or something like that.

192
00:13:33,240 --> 00:13:37,140
So multiple different zoom levels and you can play around with that.

193
00:13:37,360 --> 00:13:41,360
You could even add a functionality for the user if you want to.

194
00:13:41,820 --> 00:13:51,050
But I'm just going to assign the position as a lifelong value and then I'm going to zoom in with the

195
00:13:51,060 --> 00:13:52,310
15 F value.

196
00:13:52,350 --> 00:13:53,940
So it expects a float value.

197
00:13:53,940 --> 00:13:55,850
So I'm going to give it a float value of 15.

198
00:13:56,340 --> 00:14:02,740
And then there's one last thing to do, and that is to animate our Google map to go to this location.

199
00:14:02,760 --> 00:14:03,930
So this is a pretty cool feature.

200
00:14:03,930 --> 00:14:04,610
It looks great.

201
00:14:04,980 --> 00:14:06,120
So let's use it.

202
00:14:06,120 --> 00:14:08,180
Google map, animated camera.

203
00:14:08,820 --> 00:14:14,760
And here I'm going to use this function here and I'm going to pass a new lat long zoom.

204
00:14:16,810 --> 00:14:18,980
All right, so let's see what this returns.

205
00:14:19,000 --> 00:14:25,870
You can see it returns a camera update, and that's exactly what any camera expects.

206
00:14:25,900 --> 00:14:28,180
So you can see it expects a camera update object.

207
00:14:28,480 --> 00:14:30,040
So that works perfectly together.

208
00:14:30,050 --> 00:14:31,700
So that's why we can use it this way.

209
00:14:31,990 --> 00:14:36,190
And now this will be called, by the way, it is on map ready once the map is ready.

210
00:14:36,190 --> 00:14:36,670
Of course.

211
00:14:37,000 --> 00:14:37,360
All right.

212
00:14:37,370 --> 00:14:42,860
So as soon as our map is completely loaded, then this code here will be executed.

213
00:14:43,540 --> 00:14:48,730
And at that point, we will then zoom in to this location, which I have selected there, which is the

214
00:14:48,730 --> 00:14:49,390
Mt. Everest.

215
00:14:51,910 --> 00:14:53,680
So let's not test this again.

216
00:14:54,130 --> 00:14:57,000
Let's go over to our Mount Everest, let's view this on the map.

217
00:14:58,280 --> 00:15:03,140
And let's see how it zooms and so maps ready and you can see it zooms in all the way.

218
00:15:04,250 --> 00:15:04,760
All right.

219
00:15:05,160 --> 00:15:09,560
So now you can, of course, zoom out and you can see this is the Mount Everest.

220
00:15:10,780 --> 00:15:13,360
And it's just at the border of Nepal and China.

221
00:15:15,150 --> 00:15:17,550
All right, so there we are.

222
00:15:18,090 --> 00:15:20,630
That is pretty cool, feature 15 maybe is too much.

223
00:15:20,640 --> 00:15:23,630
Maybe you just want to use something like, I don't know, 10.

224
00:15:24,440 --> 00:15:25,620
Let's just see the difference.

225
00:15:26,620 --> 00:15:31,710
So this is the value that you can play around with just to see how deep it will zoom in.

226
00:15:32,810 --> 00:15:34,280
Or how far will zoomIn?

227
00:15:38,600 --> 00:15:41,870
So let's select Mount Everest, view this on the map.

228
00:15:45,590 --> 00:15:53,990
And you can see it zoomed in not as far as before, 15 was, of course, a super far zoomed in the screen

229
00:15:53,990 --> 00:15:57,620
here, but I think 10 is a little better for these kind of locations.

230
00:15:57,620 --> 00:15:59,330
But it really depends on the location.

231
00:15:59,330 --> 00:16:06,170
And if someone only has values or only has happy places which are very close by, then I better zoom

232
00:16:06,170 --> 00:16:07,100
would make more sense.

233
00:16:07,100 --> 00:16:07,560
Probably.

234
00:16:08,300 --> 00:16:08,840
All right.

235
00:16:09,170 --> 00:16:09,930
So that is it.

236
00:16:10,310 --> 00:16:12,620
Now you can see how you can use this functionality.

237
00:16:12,620 --> 00:16:18,590
Of course, we are still not using any location specific data, so we're not using the location of the

238
00:16:18,590 --> 00:16:19,010
user.

239
00:16:19,350 --> 00:16:22,370
And that's also something that we will implement later on.

240
00:16:22,790 --> 00:16:23,120
All right.

241
00:16:23,130 --> 00:16:24,230
So see you in the next video.

