[MUSIC] In this lecture, what I want to do is give you a brief introduction to the Map Kit Framework, and just a little bit of the concepts that you need to know in order to work with location. A real high level. This is in preparation for getting ready to do a little bit more extensive demo of Map Kit, and also, to sort of follow up on some of the things that we looked at in a previous video lecture, where we introduced the Map Kit generally. So, at a high level, what Map Kit does is, it enables you to put interactive maps into your apps. It's layered on top of another framework called core locations that includes that one as well. Core location generally provides location services, for example it can help you know where the user is going, or at least where the device is going. Where the device is, how the device is oriented, whether it's turning this way or that way with the additional compass. And then additionally map kit supplies things like maps, the graphical thing that you look at that's the map, annotations and overlays for those maps. For example, streets and points of interest. And then reverse geo coding as well. The basic things that map kit does is it is an object or what it is is it's an object that you can drop into your storyboard. And you pull it out from your object library and this is what it looks like when you search for map kit. And as it says, it displays maps, and provides an embeddable interface to navigate map content. And the class that it puts in, is called MKMapView, if you needed to subclass that for some reason. And before you do that, the Map Kit Framework has to be included into your app explicitly. And you saw an example that previously we worked with device adaptability. In your storyboard when you add a Map View, it just looks like this. It's a big blue box that has bounds like a scroll view or web view. And in this case it fills up the entire device. It's pretty basic until you start running it, of course. And when you drop it in you can limit interactions in a variety of ways. Now, normally what you expect is you expect that with a Map you would be able to zoom and rotate. You can see over here here zoom and rotate. That means that you can turn with your fingers to make the whole map rotate. You can pinch and zoom in order to make it go in and out. In this case you've also got the ability to scroll. And you've got the ability to do a three D view if you do two fingers up and down. These are things that are built in to the standard map, interface people pretty use to using those interactions but, for some reason, you had a different thing that you're doing in the map, you could limit them now, right. The down below you can also see that there is a ability to include or disclude buildings and points of interest. There's also a back stair for user location, but I recommend accessing that programatically rather than trying to do it through GUI, because there's different elements about getting permission and callbacks that happen when the user changes location that need to be handle in code. You can also choose what kind of map you want to display. So, here are our three different options. Standard means that it's an abstract map with blank color and lines representing street. Satellite is where you don't have any street names listed but you just have a view as if a camera was very high in the sky. Which, a satellite is, a camera high in the sky. I'm taking pictures of the ground and just presenting that imagery to you. Hybrid is when that image is overlaid with the lines, the points of interest, and the streets and so, you see the digital imagery of the landscape behind the roads if that's what you want. You can select them manually here in the gui when you build that next code or you can do a programmatically or you can switch it programmitcally with response to some user interaction. So interactions can be limited in variety of ways, different kinds of map can be selected and user location can be plotted but should probably be handled programmatically so that you gain permissions to use location information at the right time and at the right way. And so you can handle updates if the user is moving. Annotations is that word that UI kit and the map kit framework use for describing them as pins that get dropped onto the map. So, in this case there is a little red pen that has a little marker that marks a spot on the map. And in this case, it is marked in the location of Gradient or Sam's company does IOS development and you can see there's a little speech bubble associated with it. And that speech bubble shows up if you touch that pen and pops up with whatever information is there. When you add annotations, you specify the latitude and longitude at which you want the pin to be anchored. And so that requires knowing what the latitude and longitude is. So, just a quick overview of those things. So, latitude and longitude specifies the location on the planet and latitude. Is a description of how far north or how far south you are. The values for latitude vary between -90 and 90. -90 is the South Pole and 90 is the North Pole. Sometimes you don't see the minuses and pluses in place, and instead you see 90 north or 90 south where the south is implicitly a negative. And those numbers are degrees, so they're 90 degrees north, and 90 degrees south. When you're talking about latitude, you can think of a plane through the center of the planet that is at zero, and that is the equator, it's equivalent to the equator. Each line of latitude is like a plate that slices parallel to the Equator as you go through the planet from 0 to 90 and from 0 down to -90. Now, longitude is a little bit different. Longitude goes from -180 through 0 to +180. It goes around the circumference of the planet. 180 where's their minus 180 or plus 180 is the international dateline which goes down through the pacific ocean. Maybe not the enter. The international dateline and the 180 line of logitund isn't exactly the same because of the north side of the international dateline it veers away from the 180 line to accommodate the Aleutian islands in Alaska. Lines of launch to hover maintain that geometry and so it is a straight line at all points around the globe because we're talking not about a political division but, about a point on the planet. In contrast to latitude, reach slices like a plate, longitude, is like an orange slice and so, it is several different planes cut through the planet. With the center of all of those points is a common line between them. That line stretches from the North Pole to the South Pole, and each of the slices go through that line. And as a result, the distance from say, zero longitude to 30 longitude, the absolute distance between those two lines of longitude is greatest at the Equator. And as you go further north to the North Pole, those two lines of longitude shrink, kind of like a big triangle mapped onto the surface of the planet, because they are like orange slices. So, the zero line of longitude passes through Greenwich, England. So, Greenwich, England is that black dot there on my poorly drawn map And 00 is kind of off the south West Coast of Africa. The 0 line latitude however goes to Garnish, England for historical reasons and as you go around Africa towards China, China is on the backside of the globe, you'll go through +180 And as you go through minus 48 you cross over the United States, and South America and many other places. And you end up in the Pacific Ocean in that way. So, those two things together form a position on the planet. Latitude is a plate, and longitude is an orange slice. And what's interesting about coordinates as they're described, is that If you're familiar with plotting coordinates in some sort of graphics algorithm or maybe from just basic math where you draw graphs, traditionally you use a pair that is specified as x and y. So, x is on the x-axis and y is on the y-axis. So, x moves along the horizontal line, and y moves along the vertical line. But, a latitude/longitude pair is actually a specification where the y comes first. Dramatically or semantically, or by convention, we're used to saying latitude/longitude. But latitude specifies a plate. How far north or how far south you are, and that's conventionally the y direction. Longitude specifies where you around the planet you are and that conventionally is in extractions. That's different and if you ever find yourself trying to do some sort of a movement between and one xy position and another you may find that you get those confused if you don't remember. So, for example, the Eifel Tower located in France a little bit to the right of that black dot Is it 48.8582 degrees north and 2.2945 degrees east, and that's if you specify north and east, but if you specify just as coordinate it's plus 48.8582 and plus 2.2945 and again that's a y up and down 48. 48 is up And 2.2 is to the right of the zero line of longitude. Easter Island, the Easter Islands on the other hand are located at 27.1167 south, and 109.3667 west. Or -27, so below the equator and minus 109, or to the left of Greenwich, England, so out there in the Pacific Ocean. So, we're going to need those in order to specify points and that's what you need to work with in order to plant annotations onto the map. You may come across the term, reverse geocoding. Well, we know that for to specify an annotation, we need to know the latitude and longitude of that point sometimes you don't know the latitude and longitude of a point, and you need to get it. And once you know something like an address, for example if you know the address of a school or that you want to plot, or you know the address of a point of interest that you want to plot, you can do a process called Reverse Geocoding. And Reverse Geocoding is how you translate a location described in words, for example, an address, or a point of interest. And reverse geocoding engine returns a latitude longitude associated with that point. That process is called reverse geocoding. Again, if you want to see, if you want to do sort of a hack of a reverse geocoding, you can do as you think search in google maps for a point of interest, get the, make sure that your browser is centered on that point of interest and then, you can look in the URL for the latitude, longitude that's embedded in the URL, you can pull that out and then, that way you can do you know, hacky reverse geocode, we take a point address and you find the latitude and longitude. Google maps API offers this reverse geo coding. Apple maps also offers this reverse geo coding programatically without having to go through that work. So, now one of the things you need to do when you work with map kit is you need to obtain permission to get the user's location if in fact you want that. And that's a process that we've seen in various waves and then, something that will give a dialogue that looks like this. In this case, it says, are you going to allow map kit demo, that's the name of my app that I was using more to create this dialogue. To use your location when you use the app and so, getting this location you know, location usually requires obtaining their permissions, that's something that you tackle. First, if you want to keep track of a user while they move so, if you want to monitor, uses location in your app. The way you do that is you implement a delegate function and so, the IOS is keeping track of where the user is going as I move along somewhere and in your app, you're going to write a code that has delegate. That will get called every time the user makes a significant location change. And then you have to decide what you want to do with that location. But the delegate pattern is the way that iOS informs your app that a change has been made, for the devices location. Geofencing is also something that's available, we're not going to cover it in this course, we'll cover it in a future course, I hope. But what that enables you to do is it enables you to specify a location on a map in different ways. You could specify it with bounds or you can specify it as a distance from a point. And rather than just monitoring every single place that user goes. Instead what you can do is you can detect when a user enters that location or if they're already in that location, you can detect where they depart from that location. And so, whenever that boundary gets crossed, you can get a notification in your code that the boundary has been crossed. And that's called geofencing. And the reason why you might want to use that, is for example, the way reminders, the app that's built into iOS, enables you to have effects like Reminding me to take out the garbage when I get home. Getting home is a geofence. The IOS application knows where your home is based on your contact book. And so, when you get near your home, the enter the geofence region gets triggered and the reminder app pops up an alert saying that you're near home, so don't forget to take out the garbage or whatever it is. So, specifying a region where you come in and out and getting notifications for that, that's called geofencing. You can also of course get directions, this is something we're used to now from map applications you can build this into your map application if you like. So, in this case here's a map going from Santa Barbara to the Apple store. In down town L.A this is something you can access programatically in your MapKit. And you can also do searches that are geographically aware so here is searching a search apple store near me and you get a bunch of annotations that come up that are provided by MapKit for where Apple stores are. That's actually not near me so I dont know how it figured out that, oh that's where the simulator thinks it is. The simulator always thinks it's near Apple's headquarters. So, within the Map Kit is programmatic access to the search functionality. Okay, so in summary. Maps and location are really a great way to provide awareness of the physical environment which a user and their device and subsequentially the app are in. And of course mobility is really a key feature in iOS based computing, being able to move a device around and move your body and. And be in different places while you're running your app is really something that's unique to this kind of computing. So, Map Kit enables, and core location services, enable you to react to that. And finally, Map Kit supports the most common functionality that you're familiar with in mapping applications out of the box, so we're going to leverage that. In our applications. Yep, so that's what I want to say about Map Kit and Map Kit functionality in this lecture. Thanks for your attention, we'll address some more of this in the future. [MUSIC]