Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the framework needed to use maps in Swift.
iOS Swift
import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing UIKit instead of MapKit.
Importing CoreLocation which is for location but not maps.
✗ Incorrect
MapKit is the framework used to work with maps in iOS apps.
2fill in blank
mediumComplete the code to create a map view and add it to the main view.
iOS Swift
let mapView = MKMapView()
view.[1](mapView) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using removeSubview which deletes a view.
Using bringSubviewToFront which only changes view order.
✗ Incorrect
To show the map, you add the MKMapView as a subview to your main view.
3fill in blank
hardFix the error in setting the map region center coordinate.
iOS Swift
let coordinate = CLLocationCoordinate2D(latitude: 37.7749, longitude: [1]) let region = MKCoordinateRegion(center: coordinate, latitudinalMeters: 1000, longitudinalMeters: 1000) mapView.setRegion(region, animated: true)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number for longitude.
Using latitude value again instead of longitude.
✗ Incorrect
Longitude must be a Double number, not a string or other value.
4fill in blank
hardFill both blanks to create a map annotation and add it to the map.
iOS Swift
let annotation = MKPointAnnotation() annotation.[1] = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060) annotation.[2] = "New York City" mapView.addAnnotation(annotation)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtitle instead of title for the main label.
Trying to set region on annotation which is not valid.
✗ Incorrect
Annotations need a coordinate and a title to show on the map.
5fill in blank
hardFill all three blanks to create a region centered on a coordinate with a span and set it on the map.
iOS Swift
let center = CLLocationCoordinate2D(latitude: 34.0522, longitude: [1]) let span = MKCoordinateSpan(latitudeDelta: [2], longitudeDelta: [3]) let region = MKCoordinateRegion(center: center, span: span) mapView.setRegion(region, animated: true)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using large span values which zoom out too far.
Using positive longitude for a west coast city.
✗ Incorrect
Longitude must be a number, and the span values control zoom level with small deltas.