This course explores maps and how we can integrate them into our apps. We'll leverage map functions like finding the user location, showing the user's location on the map, and choosing a location on the map to get its coordinates. And in order to do that, we're going to be focusing on an app called Travel Book. We're going to integrate Core Data in this Travel Book as well so that we can re-practice what we have learned in the previous section.
Intended Audience
This course is designed for anyone who wants to:
- Learn about iOS development and coding
- Move into a career as an iOS developer
- Master Swift skills
Prerequisites
To get the most out of this course, you should have some basic knowledge of iOS.
Hi, within this lecture, we're going to start building our Travel Book, and first thing to do will be to learn how to work with maps. It's fairly easy. You just bring in one view and you just start working with maps. Thanks to something called Map Kit in the Swift, okay? I'm just going to go ahead and create my project and I'm going to go for a single view app as usual, okay? And then, here I'm going to check the Use Core Data one more time because we will be saving all of this information into Core Data. And for product name, I'm going go for TravelBook. So, click 'Next' and place this under my IOS complete folders you can place it wherever you want, and then I'm going to make it into a full screen mode so that we can see it better and I'm just going to go ahead and show you that we have this TravelBook, its Core Data model but we're not going go into that right now, we first have to learn how to work with maps then we can just go on and save our information into Core Data model because we already know how to work with Core Data, right? So, let's go to storyboard because in order to work with maps we're going need a Map View and it's fairly easy to work with maps. You just open your library, search for map and you will see something called Map Kit View, okay? Just drag and drop the Map View. As you can see this is a regular view like we used to work with other views before like UI imagery you can just drag and drop here and you can stretch it out for the all edges, for example, you can come over here and just say 000 for all constraints and it will stretch out all to the edges. Now, when we run this, when we set this up we will see a whole huge map covering up all the View Controller. In order to set this up, I'm going to open my View Controller in an assistant editor and I'm going to define this map by dragging and dropping here and I'm going to call this mapView, okay? And once we do that, we'll get an error. So, we have to do some set up first and it's fairly easy to do that. So, we're going to have to use viewDidload because we have to set the delegate of this mapView to the View Controller like we do in the tableViews, right? So, this is all we have to do to make this work. As you can see, this is saying undeclared type. So, let me just say mapView.delegate is self and this is not going away because we have to make our ViewController delegates of MKMapKitView as well but in order to do that we first have to import MapKit. So, import MapKit make mapView.delegate equal to self and then come over here to ViewController and just say MK, okay? MKMap, Yes, this from MKMapViewDelegate. So, this is exactly like what we do in the tableViews, right? So, we set delegate to self and we make our ViewController as an actual delegate of the related view. So, import MapKit, say this is an MKMapViewDelegate and then mapView.delegate is self. So, later on we're going to use another delegates as well because we're going to need a lot of functions to be called in our ViewController but for right now, this is all we need to make this map run. So, if I run this in my simulator then I will get a map and it won't show me any location of the user, it won't show me any specific location, we're just going to see the map. And we can wander around the map, we can zoom in zoom out, whatever we want but it won't do any action because we haven't defined one yet. For example, we are in the Europe, we can zoom in, we can zoom out, we can do whatever we want with this map but we're just displaying the map right now, we're not doing anything fancy. And let me zoom in, so let's see if we can see the details over here. As you can see the cities' names are appearing here right now. So, it seems fine. I believe this is all for this lecture, we're going to stop here. And within the next following lectures, we're going to learn how to get the user location so we can start this map actually at the user's location. And then after that, we're going to learn how to pin this map view in order to tag the view and get the co-ordinates of that specific view so that we can later on add a navigation to it. Let's do all of this in the following lecture.
Atil is an instructor at Bogazici University, where he graduated back in 2010. He is also co-founder of Academy Club, which provides training, and Pera Games, which operates in the mobile gaming industry.