image
Map Details
Start course
Difficulty
Intermediate
Duration
3h 18m
Students
24
Description

In this course, we're going to build a Foursquare Clone using Parse. Parse provides you with a great tool to work in cloud servers and you will learn the advantages and disadvantages that come with it.

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.

Transcript

Hi. Within this lecture we're going to add the function that is necessary to zoom into the chosen location in our details view controller. So far, we're getting all the data that we need from Parse and we are showing the details to the user. But right now even though we have this chosen latitude and longitude, we didn't go into the maps and just zoom into that latitude and longitude. So, after we get this latitude and longitude we may continue to do that under this function, right?

Because we cannot do that under viewDidLoad actually. Let's try to do that under viewDidLoad and you will see why we cannot do that under viewDidLoad. We have to do that in here, because this query actually works asynchronously so that when we try to do something under viewDidLoad, maybe we won't have that data. So, what do I mean? For example, after having this getDataFromParse executed, let's try to call this chosen latitude and longitude and let's try to print them. So, even though we call this getDataFromParse, and even though after we print this we still get this as 0.0, the initial value of this chosen latitude. Why is this happening? Because this works asynchronously, and even though we just call this after we execute this, since it's not being synchronously, it won't print out. So, if I print out in here, okay? After we get this, then this will be called in order and after we get this longitude then we can display it in the logs. As you can see now we have the right parameter. So, when you try to work with asynchronous functions, if you do something, if you want to do something with order then you have to do this inside of your asynchronous function as well. So, I'm going to do this over here. So, these are O for object operations, okay, objects. And I'm going to continue my maps operations under the same function as well. So, I'm going to create a Location and this will be a sphere location, coordinate 2-D, and this will ask me for a latitude and longitude. So, let's try to get selsf.chosenLatitude and self.chosenLongitude. Yep, so this is good. And let's try to create a span. Again, we're going to use the MKCoordinateSpan, MKCoordinateSpan. And this will ask us for a latitudeDelta and latitudeDelta will be 0.035, and longitude will be 0.035. And I'm going to create an MKCoordinate region. So, this will ask me for a center and a span. And center will be location, span will be span. And then I can call my map view, okay? DetailsMapView, not imageView, detailsMapView. Then I can just say detailsMapView.setRegion, and I'm going to focus on that region with that animation. So far so good. Let's try this. Let's see if we can see the chosen location zoomed in. If we can, then we're going to have to add an annotation as well. Here we go, it zooms in the Amsterdam. So, it's working. So, we have to show the exact selected location with an annotation as well of course. So, let me create my annotation. So, this will be MKPointAnnotation and this will be, actually we have to give some coordinates. So, annotation.coordinate is the location that we have just created, right? And if we want we can give some title and subtitle as well. We already have our title and subtitle over here, right? And we assigned it to be our details name label. So, we can come over here and say annotation.cordinates. I believe I have deleted something. So, this will be our location and annotation.title will be details self.place, details. No, this is not this one. detailsNameLabel, I believe. detailsNameLabel.text, yep, this one. And we can have a subtitle as well, annotation.subtitle is going to be self.detailsTypeLabel.text. And finally we can add this annotation to our mapView. Say self.detailsMapView.addAnnotation, okay? And give this annotation. Here we go. Now let's test this and see if we can get the James Restaurant pinned in on our map. Let's click on this. Here we go. Now we see the James Restaurant. Let me click over here to zoom in. If I just hit over here we will see the title and the subtitle as we want. So, the only thing left to do to finish our app is to add navigation button over here. Remember we have something called disclosure button and that's what we're going to add in the next lecture to open our maps and do some navigation from our current location to the selected place.

About the Author
Students
2095
Courses
55
Learning Paths
3

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.

Covered Topics