Challenge - 5 Problems
MapKit Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediateMap 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)
Attempts:
2 left
💡 Hint
Think about what MKPointAnnotation does by default in MapKit.
✗ Incorrect
By default, MKMapView shows a red pin for MKPointAnnotation. When tapped, it shows the title in a callout bubble.
❓ lifecycle
intermediateRequesting Location Authorization
Which method should you call to request the user's permission to access location data when using MapKit in iOS?
Attempts:
2 left
💡 Hint
The location manager handles permissions, not the map view.
✗ Incorrect
You must call requestWhenInUseAuthorization() on CLLocationManager instance to ask for permission.
advanced
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
}Attempts:
2 left
💡 Hint
Use MKCoordinateRegion with meters for zoom level.
✗ Incorrect
MKCoordinateRegion(center:latitudinalMeters:longitudinalMeters:) creates a region centered on the coordinate with a span in meters. setRegion updates the map view.
📝 Syntax
advancedCorrect Delegate Method Signature
Which is the correct signature for the MKMapViewDelegate method that provides a view for an annotation?
Attempts:
2 left
💡 Hint
Check the parameter labels and return type carefully.
✗ Incorrect
The correct delegate method is func mapView(_:viewFor:) returning an optional MKAnnotationView.
🔧 Debug
expertWhy 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?
Attempts:
2 left
💡 Hint
The blue dot requires permission to access location data.
✗ Incorrect
Without user permission, the map cannot show the user location even if showsUserLocation is true.
