Topics Covered in This iOS Development Tutorial:
Adding the MapKit Framework, Adding a Map View, Setting a Custom Location, Defining Location Coordinates, Adding Auto Layout
Exercise Preview

This exercise builds upon previous tutorials (1B-2C). Ensure you have completed the foundational exercises or use the provided starter project to maintain consistency in your development environment.
Exercise Overview
In this exercise, we'll integrate Apple's MapKit framework to display an interactive map showing the Jive Factory's location. This hands-on tutorial demonstrates essential skills for any iOS developer working with location-based features—a cornerstone of modern mobile applications. By the end of this exercise, you'll understand how to embed maps, configure custom locations, and implement proper Auto Layout constraints for responsive design across all iPhone screen sizes.
Getting Started
If you completed the previous exercise, you can skip the following sidebar. We strongly recommend completing exercises 1B–2C sequentially to build upon established concepts and maintain project continuity.
If you completed the previous exercise, Jive Factory.xcodeproj should remain open in Xcode. If you closed it, navigate to yourname-iOS Dev Level 2 Class > Jive Factory and reopen the project.
If You Did Not Complete the Previous Exercises (1B–2C)
- Close any open files and return to the Desktop.
- Navigate to Class Files > yourname-iOS Dev Level 2 Class.
- Duplicate the Jive Factory Ready for Location Map folder.
- Rename the duplicated folder to Jive Factory.
- Open Jive Factory > Jive Factory.xcodeproj in Xcode.
Project Setup Process
Navigate to Class Files
Close existing files and navigate to Desktop > Class Files > yourname-iOS Dev Level 2 Class directory
Duplicate Starter Project
Duplicate the 'Jive Factory Ready for Location Map' folder and rename it to 'Jive Factory'
Open Project File
Launch Jive Factory.xcodeproj to begin the MapKit integration exercise
Adding the MapKit Framework
MapKit represents one of Apple's most powerful and feature-rich frameworks for location services. To incorporate mapping functionality into our application, we must first add Apple's MapKit.framework to our project dependencies. This framework provides comprehensive mapping capabilities including interactive gestures (zooming, panning), location services, custom annotations, and route calculations. In iOS development, frameworks serve as pre-built collections of code, libraries, UI components, and resources that extend your app's capabilities without requiring you to build these complex systems from scratch.
Click on the Jive Factory project name at the top of the Project navigator. This action opens Xcode's Project Settings Editor, where you configure build settings, capabilities, and framework dependencies.

If the projects and targets sidebar isn't visible, click Show projects and targets list
located in the upper-left corner above the Identity section.Under the Targets section, ensure Jive Factory is selected. Targets define how your project builds into a final product—in this case, an iPhone application.

- Click the Build Phases tab. This section controls the compilation and linking process for your application.
- Expand the Link Binary With Libraries section to view currently linked frameworks.
- Click the Add items button
located in the bottom-left corner of this section. - In the framework search bar, type: map
- From the filtered results, double-click MapKit.framework to add it to your project dependencies.
Verify the integration by checking the Project navigator—you'll notice Xcode automatically created a Frameworks folder containing MapKit.framework. This organizational structure keeps your external dependencies clearly separated from your custom code.
Framework Integration Checklist
Opens Project Settings Editor for configuration
Ensures framework is linked to correct target
Access linking configuration options
Provides map functionality and UI elements
Adding a Map View
Now that MapKit is properly integrated, we'll add the visual map component to our user interface. The Map Kit View provides users with familiar map interactions while giving developers programmatic control over location, zoom levels, and custom annotations.
- In the Project navigator, select Main to open the storyboard editor.
- Ensure your Interface Builder canvas is set to 100% zoom for precise positioning when adding the Map Kit View component.
- In the Object library
search field, type: map From the Object library
, drag the Map Kit View onto the Map View Controller in the Editor area. Exercise caution to avoid dragging onto the tab bar area or positioning it so it overwrites the existing view controller. During the drag operation, you should see positioning guides like this:
Professional Tip: If you accidentally overwrite the existing view, immediately press Cmd–Z to undo and retry the Map Kit View placement. Proper UI component positioning is crucial for maintaining clean view hierarchies.
Resize the Map Kit View to fill the entire iPhone screen by dragging the corner and edge handles. This creates an immersive map experience for users.
- Ensure the Map Kit View remains selected in the Interface Builder editor.
- In the Utilities panel, click the Attributes inspector tab
to access map-specific configuration options. - In the Map View configuration section, locate Shows and enable User Location. This feature displays a blue dot indicating the user's current position when location services are available.
- Test the current implementation by clicking the Run button to launch the iOS Simulator.
- Once the Simulator loads completely, tap the Map tab to view your integrated map.
When prompted with a location services alert, tap OK to grant permission.
Note: The iOS Simulator cannot access actual GPS coordinates, so user location won't display. On physical devices, this feature shows the user's real-time location with remarkable accuracy.
Test the map's interactive capabilities by simulating zoom gestures. Hold the Option key to display two gray circles representing fingertips. Click and drag to simulate pinch-to-zoom functionality. This interaction pattern is fundamental to modern mobile user experience design.
When dragging Map Kit View from Object library, avoid positioning over the bottom tab area or overwrapping existing views. Use Command-Z to undo if you accidentally overwrite the existing view structure.
Map View Configuration
Add Map Kit View
Drag Map Kit View from Object library onto Map View Controller at 100% zoom level
Resize to Fill Screen
Drag handles to resize Map View to match iPhone screen dimensions
Enable User Location
Check 'Shows User Location' in Attributes inspector for location tracking capability
Setting the Jive Factory Location
While displaying user location is valuable, our business objective requires showcasing the Jive Factory's specific location. This involves creating custom view controller logic and integrating programmatic map controls—essential skills for any location-aware iOS application.
- Return to Xcode from the Simulator.
- In the Project navigator, select BandDetail.swift. This selection determines where Xcode will position the new file in your project structure.
- Press Cmd–N to create a new file.
- Double-click Cocoa Touch Class to select this iOS-specific template.
- From the Subclass of dropdown menu, select UIViewController (you can begin typing and let Xcode's intelligent autocompletion assist you).
- Set the Class name to: MapViewController
- Click Next to proceed.
- Verify you're saving within the Jive Factory folder, then click Create.
- Confirm that MapViewController now appears in the Project navigator's file list.
- Return to the storyboard by clicking Main in the Project navigator.
- Deselect all elements by clicking an empty area of the Interface Builder canvas.
- Select the Map View Controller by clicking its top navigation bar, which should highlight the entire controller with a blue outline.
- In the Utilities area, click the Identity inspector tab
to access class binding options. - Under Custom Class, begin typing Map in the Class field. Xcode should autocomplete to MapViewController—press Return to confirm the binding. If autocomplete doesn't trigger, type the full class name manually.
- If the Document Outline panel is open, click Hide Document Outline
to maximize workspace efficiency. - Click the Adjust Editor Options button
in the upper-right corner and select Assistant to enable split-screen editing between the storyboard and code. - If MapViewController.swift doesn't automatically appear in the Assistant editor, click the storyboard's Map View Controller title bar and select the appropriate file from the context menu.
Below the existing import UIKit statement (approximately line 10), add the MapKit framework import:
import UIKit import MapKit class MapViewController: UIViewController {Create an IBOutlet connection by holding Control and dragging from the MK Map View in the storyboard to the code area below the class declaration, as illustrated:

In the connection configuration popup, specify these settings:
Connection: Outlet Name: jiveMapView Type: MKMapView Storage: Weak - Click Connect to establish the outlet relationship.
Navigate to MapViewController.swift in the Project Navigator to begin implementing the location logic.
Custom Map View Controller Setup
Create New Class
Generate MapViewController as UIViewController subclass
Connect to Storyboard
Link Map View Controller to MapViewController in Identity inspector
Create IBOutlet
Control-drag from MK Map View to create jiveMapView outlet connection
Defining Location Coordinates
Professional map implementation requires precise coordinate specification and zoom level configuration. We'll define the Jive Factory's exact geographical position using latitude and longitude coordinates, plus a span value controlling the map's zoom level. These constants ensure consistent map presentation across all user interactions.
- Navigate to File > Open in the menu bar.
- Browse to Desktop > Class Files > yourname-iOS Dev Level 2 Class > Code Snippets and open mapCoordinates.txt.
- Select all content with Cmd–A.
- Copy the code using Cmd–C.
- Close the text file.
- In the Project navigator, select MapViewController.swift.
- Locate the @IBOutlet weak var jiveMapView: MKMapView! declaration.
Create space above the outlet and paste the coordinate constants:
class MapViewController: UIViewController { let jiveLatitude = 40.72004 let jiveLongitude = -74.003912 let jiveSpan = 0.05 @IBOutlet weak var jiveMapView: MKMapView!These constants define the Jive Factory's precise location (latitude and longitude) and zoom level (span). For professional applications, you can obtain accurate coordinates using services like Google Maps, Apple Maps, or specialized geocoding APIs. The span value determines the visible map area—smaller values create closer zoom levels, while larger values show broader geographical regions.
We'll leverage MapKit's MKCoordinateRegion class to configure our map display. An MKCoordinateRegion combines a center coordinate point with a span defining the visible area around that center.
- Navigate to the viewDidLoad method in your MapViewController.
Replace the default comment with code to initialize a map region:
override func viewDidLoad() { super.viewDidLoad() var jiveRegion = MKCoordinateRegion() }This creates a jiveRegion object using MapKit's MKCoordinateRegion structure.
Add a center point coordinate object:
override func viewDidLoad() { super.viewDidLoad() var jiveRegion = MKCoordinateRegion() var center = CLLocationCoordinate2D() }Configure the center point using our predefined coordinate constants:
var jiveRegion = MKCoordinateRegion() var center = CLLocationCoordinate2D() center.latitude = jiveLatitude center.longitude = jiveLongitude }Create a span object to control the zoom level:
center.longitude = jiveLongitude var span = MKCoordinateSpan() }Set the span's latitude and longitude deltas to create uniform zooming:
var span = MKCoordinateSpan() span.latitudeDelta = jiveSpan span.longitudeDelta = jiveSpan }Apply the center point and span to the region object:
span.longitudeDelta = jiveSpan jiveRegion.center = center jiveRegion.span = span }Configure the map view to display our custom region with smooth animation:
jiveRegion.span = span jiveMapView.setRegion(jiveRegion, animated: true) }- Test the implementation by clicking the Run button.
- After the Simulator launches, tap the Map tab. The map now centers on the Jive Factory's New York location, but you'll notice it lacks a location pin. We need to add a map annotation to provide visual location indication.
- Return to Xcode to implement the annotation feature.
After the region configuration code, add an annotation object:
jiveMapView.setRegion(jiveRegion, animated: true) let jivePoint = MKPointAnnotation() }Configure the annotation with location data and descriptive information:
let jivePoint = MKPointAnnotation() jivePoint.coordinate = center jivePoint.title = "The Jive Factory" jivePoint.subtitle = "580 Lispenard, NY, NY 10013" }Add the configured annotation to the map view:
jivePoint.subtitle = "580 Lispenard, NY, NY 10013" jiveMapView.addAnnotation(jivePoint) }- Click Run to test the complete implementation.
- Navigate to the Map tab in the Simulator.
Excellent! Your map now displays a precise red pin marking the Jive Factory's location. Tap the pin to reveal the title and subtitle information you configured, providing users with essential location context.
Location Coordinate Components
Latitude Value
40.72004 represents the north-south position of Jive Factory in New York City coordinate system.
Longitude Value
-74.003912 represents the east-west position using negative values for western hemisphere locations.
Span Control
0.05 determines zoom level precision, with smaller values providing closer, more detailed map views.
MapKit Implementation Process
Create MKCoordinateRegion
Establish region object with center point and span properties for map area definition
Configure CLLocationCoordinate2D
Set latitude and longitude values using predefined constants for precise location targeting
Define MKCoordinateSpan
Establish zoom level using latitudeDelta and longitudeDelta properties for optimal view
Apply Region to Map View
Use setRegion method with animation to smoothly transition to specified location
Adding Auto Layout
Professional iOS applications must provide consistent user experiences across Apple's diverse device ecosystem. Auto Layout constraints ensure your map interface adapts seamlessly to different screen sizes, from iPhone SE to iPhone Pro Max, maintaining optimal proportions and usability regardless of device dimensions.
- Select the MK Map View component in the storyboard.
- Click the Add new constraints button
located at the bottom-right of the Interface Builder editor. - In the constraints popup, ensure Constrain to margins is unchecked for edge-to-edge map display. Verify all four constraint values are set to 0.
- Under Add New Constraints, notice the four red dotted lines surrounding a central white box. Click all four lines to activate constraints for top, bottom, leading, and trailing edges.
Click Add 4 Constraints to apply the configuration:

Technical Note: These constraints pin the map view to all four edges of its parent view, ensuring the map fills the entire screen real estate on any device size. This creates an immersive, full-screen map experience that adapts dynamically to different iPhone models.
- Test responsiveness across device sizes by changing the active scheme to iPhone 13 Pro Max.
- Run the application to verify proper scaling.
- After the Simulator loads, tap the Map tab to confirm the map fills the larger screen perfectly.
- Return to Xcode for additional testing.
- For comprehensive testing, experiment with other device sizes such as iPhone SE or iPhone 15. This validates your Auto Layout implementation across Apple's entire device range.
Maintain the current file state. The next exercise will demonstrate integrating external web content directly within your application, building upon the location features you've just implemented.
Auto Layout constraints ensure your map view adapts perfectly across all iPhone screen sizes, from iPhone SE to iPhone 13 Pro Max, maintaining consistent edge-to-edge coverage.
Constraint Configuration Steps
Ensures constraints apply to correct view element
Allows map to extend to screen edges
Creates edge-to-edge map coverage
Activates top, bottom, leading, and trailing constraints