Hint: MKPointAnnotation + addAnnotation = pin on map [OK]
Common Mistakes:
Thinking MKPointAnnotation is invalid for pins
Believing coordinate must be set differently
Forgetting to add mapView to view (not shown here)
5. You want to show a map centered on New York City with a zoom level that shows a small area around it. Which code correctly sets this region using MapKit?
hard
A. let center = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060)
let span = MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1)
let region = MKCoordinateRegion(center: center, span: span)
mapView.setRegion(region, animated: true)
B. let center = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060)
let span = MKCoordinateSpan(latitudeDelta: 10, longitudeDelta: 10)
let region = MKCoordinateRegion(center: center, span: span)
mapView.setRegion(region, animated: true)
C. let center = CLLocationCoordinate2D(latitude: 0, longitude: 0)
let span = MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1)
let region = MKCoordinateRegion(center: center, span: span)
mapView.setRegion(region, animated: true)
D. let center = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060)
mapView.region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0, longitudeDelta: 0))
Solution
Step 1: Understand latitudeDelta and longitudeDelta
Smaller delta values zoom in closer; 0.1 is a small area, 10 is very large.
Step 2: Check each option's center and span
let center = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060)
let span = MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1)
let region = MKCoordinateRegion(center: center, span: span)
mapView.setRegion(region, animated: true) uses correct NYC coordinates and small span for zoom. let center = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060)
let span = MKCoordinateSpan(latitudeDelta: 10, longitudeDelta: 10)
let region = MKCoordinateRegion(center: center, span: span)
mapView.setRegion(region, animated: true) zooms out too far. let center = CLLocationCoordinate2D(latitude: 0, longitude: 0)
let span = MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1)
let region = MKCoordinateRegion(center: center, span: span)
mapView.setRegion(region, animated: true) centers at (0,0), wrong city. let center = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060)
mapView.region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0, longitudeDelta: 0)) uses zero span, which is invalid.
Final Answer:
let center = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060)
let span = MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1)
let region = MKCoordinateRegion(center: center, span: span)
mapView.setRegion(region, animated: true) -> Option A
Quick Check:
Small span = zoom in; correct center = NYC [OK]
Hint: Small latitudeDelta/longitudeDelta zooms in; use correct center [OK]
Common Mistakes:
Using large span values for zooming in
Setting center to wrong coordinates
Using zero span which disables zoom
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.