So let's go out and construct our map of view.
All right so we could create this map view somewhere else but I'm just going to put in sort of a quick
detail just to simplify our lives.
OK.
Someone has to come down here say struct and call this map view.
OK.
And then this will confirm to the you eye view represented all as such.
OK.
Just we don't forget.
I'm going to go ahead and import if you frameworks here.
So the first four Mark I'm going to use here and then just add Foundation just in case we need it and
I'm going to add another import here which no you I hit.
That's very important.
And yet another one.
This one is going to be the map kit such because we need that.
All right.
So we have our map view here.
Now we're going to go ahead and start constructing this map for you.
Well first of all this map view will need data.
So unless a far data is and we are going to parse features because that's where we get all of the information
from the API so we can say var data.
And this is going to be features such very good.
The next thing we need to do here is we need to actually override a function whenever we are conforming
to your wife your presentable we need to override the make you eye view.
So say func make it the moment you start typing.
Make you eye view.
There it is.
And this here is where we actually going to run the code which is going to be read by SWIFT to our engine
to actually show the map.
So in this case here there's a few things happening but the first thing we need to do here is that the
context I don't need to pass everything I was going to go ahead and say I want to be just the general
context as such and I don't need to pass any type that we're expecting.
OK.
And in this case here I'm just gonna go read of the right type of you as such.
So we just expected to return a map view like that.
Next we're just going to use the M K map view.
This one there and we're going to just pass frame that zero.
Right.
So just a generic frame here rectangular whose origin and size are both zero.
So a good starting point.
All right.
Now we're having an issue here.
That's because it shouldn't be just map view.
Should it be M.K..
Should we go to the actual M K map the Wasatch.
There we go.
Now we have no problem.
And we'll she'll have a problem here.
No worry we gonna ignore it because we can actually keep doing what we're doing here.
And the next thing we need to have here is to override the app data UI view.
I'm going to say func update you I view there it is.
And for our app did you I view.
We are passing a map kit map view.
We're passing our context which in this case here we're going to do the same what we did before just
a generic context as that.
And we don't need to specify anything there.
OK just like this and wallah now the app they view as the name imply this is where the view is going
to be updated meaning this is where we can actually write out the user interface.
In this case our map.
So the construction of our map is happening here.
I think I've said that it's going to happen here but not really here we just like making sure that we
have the view to show the map right to the actual work happens inside here.
Next to create an annotation an annotation is an object that allows us to create all sorts of things
to construct an actual point that we are going to put in a map.
OK.
And I say let annotation and there's a lot of things you can do with it or add to it you will see in
a second can be OK.
Notice we are using the M K prefix here.
Right.
It says at the bottom the m k it's an embedded bowl map interface similar to the one provided by the
maps application.
So we're using that in this case we actually going in and we want to create a point annotation.
OK.
There we go.
Creating that object there and then we're going to create coordinates which is the actual location longitude
and latitude and I'm less a c l l location.
OK but I don't want just the normal one I want this location coordinate to D.
That's what we need to create what we need.
Now these takes in a latitude and longitude.
Now where do we get those values of latitude and longitude.
Well those values we get from our API of course but most importantly notice that our API here is very
strange because it says geometry and then it's an array of coordinates.
OK.
So there's three items in his coordinates which means we have to use the index and go through and find
exactly the values we want.
The other thing also here to remember is that the first value which is value zero is longitude and the
first one is latitude.
And this third one is some other value which we have no interest in.
So let's go back to our code here and start getting that.
So we have the data here which is handy because we need that to fill with our latitude and longitude.
So for our longitude I'm gonna say data dot when I go to geometry right and go to coordinates.
Look it even gives us help here.
So when the coordinates and I want to go and get the first the value because I know it's an array I
can just go ahead and pass one like that.
OK.
And for longitude same thing.
Data geometry and coordinates and I want of course the zero index value.
I think I should say this was the second value because this is the first one but you get the point here.
All right.
Very good.
Making good progress here we have a few warnings but they will go away soon enough.
It makes me going to create a spans when say let span it's going to be equal to and K coordinates span.
There is such an object which means we need to then pass a few parameters here.
So like you delta here we get pass just one point zero and longitude also one point zero.
There's a span there.
And once we have that information then we need to set a region now to set a region we need to use the
UI view because this is the actual map view.
OK so what's happening here if you think about it is we creating all the pieces that we need to then
have the mark on the map.
OK.
So next here we can create a region.
So I I say let region it's going to be again.
M.K. coordinate region all very helpful here.
And I want to center like that to be coordinate that we are created and the span is gonna be the span
that we also created here because it makes sense.
So now the region here we are passing the coordinates.
Now we are kind of triangulating the location that we wanted by creating this little region here.
And we passed the span which we added there.
So once we have all those pieces now we are able to get to the map view which was being passed as you
eye view there.
See you eye view.
Be careful that you need to get the exact one here.
So why you like that dot.
When I set the region to what.
Well the region is going to be the region that we just created and animated.
Meaning you want this to be animated when it shows.
Sure why not.
OK very good.
So then we are going to use our annotation here.
Right.
Because this annotation we can add all sorts of information to it.
The information we get our intention is one the coordinates we can add a title we can add a subtitle
and so forth.
Right.
So when I say annotation I'm going to pass the coordinate here it's going to be equal to the coordinate
that we created.
Let's make this coordinate because there's just one that's probably better.
Strange that to coordinate.
Very good.
So going to be able to coordinate like this and the title right.
It's gonna be equal to data that properties that plays annotation we can even add.
Let's see subtitle.
We want this to be something that would say magnitude and then I data properties mag like that.
OK.
Now once we have the region which we adding to our set region and we are adding things or orientation
well we need to pass that annotation into our UI view.
So we say you I view which again is the same view here which we actually set up the region so you I
view again that ad annotation there is indeed that method we can use.
So what annotation.
Well the one we've been working on this one here.
So now our view which you remember it is indeed our map view the actual map has a point that we have
added which contains all these annotation which has coordinates.
We have the place name as a title and a subtitle is going to just show us the magnitude of that place.
Very good.
So now we have our map view here which we can call inside of earthquake details in that it's going to
happen in the next video.