0
0
iOS Swiftmobile~20 mins

MapKit for maps in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
MapKit Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
Map Annotation Display
You add an annotation to a MKMapView. What will the user see by default when the app runs?
iOS Swift
import MapKit

let mapView = MKMapView()
let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194)
annotation.title = "San Francisco"
mapView.addAnnotation(annotation)
ANothing appears on the map because annotations need a custom view to display.
BThe map zooms automatically to the annotation location but no pin is shown.
CThe map shows a blue dot at the coordinates but no pin or title.
DA pin appears on the map at the specified coordinates with a callout showing "San Francisco" when tapped.
Attempts:
2 left
💡 Hint
Think about what MKPointAnnotation does by default in MapKit.
lifecycle
intermediate
1:30remaining
Requesting Location Authorization
Which method should you call to request the user's permission to access location data when using MapKit in iOS?
AmapView.startUpdatingLocation()
BlocationManager.requestWhenInUseAuthorization()
CCLLocationManager.requestAuthorization()
DmapView.requestLocationAccess()
Attempts:
2 left
💡 Hint
The location manager handles permissions, not the map view.
navigation
advanced
2:30remaining
Centering Map on User Location
You want the map to center on the user's current location once it is found. Which code snippet correctly updates the map's region?
iOS Swift
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    guard let location = locations.last else { return }
    // Update map region here
}
AmapView.setCenter(location.coordinate, animated: false)
BmapView.region = MKCoordinateRegionMakeWithDistance(location.coordinate, 500, 500)
C
let region = MKCoordinateRegion(center: location.coordinate, latitudinalMeters: 500, longitudinalMeters: 500)
mapView.setRegion(region, animated: true)
D
mapView.centerCoordinate = location.coordinate
mapView.zoomLevel = 15
Attempts:
2 left
💡 Hint
Use MKCoordinateRegion with meters for zoom level.
📝 Syntax
advanced
1:30remaining
Correct Delegate Method Signature
Which is the correct signature for the MKMapViewDelegate method that provides a view for an annotation?
Afunc mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?
Bfunc mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView
Cfunc mapView(_ mapView: MKMapView, annotationViewFor annotation: MKAnnotation) -> MKAnnotationView?
Dfunc mapView(_ mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView
Attempts:
2 left
💡 Hint
Check the parameter labels and return type carefully.
🔧 Debug
expert
2:00remaining
Why Does the Map Not Show User Location?
You set mapView.showsUserLocation = true but the blue dot does not appear. What is the most likely cause?
AYou forgot to request location authorization from the user.
BThe mapView delegate is not set.
CThe mapView frame is zero size.
DYou did not add an annotation for the user location.
Attempts:
2 left
💡 Hint
The blue dot requires permission to access location data.