0
0
iOS Swiftmobile~10 mins

MapKit for maps in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
AMapKit
BUIKit
CFoundation
DCoreLocation
Attempts:
3 left
💡 Hint
Common Mistakes
Importing UIKit instead of MapKit.
Importing CoreLocation which is for location but not maps.
2fill in blank
medium

Complete 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'
AinsertSubview
BremoveSubview
CaddSubview
DbringSubviewToFront
Attempts:
3 left
💡 Hint
Common Mistakes
Using removeSubview which deletes a view.
Using bringSubviewToFront which only changes view order.
3fill in blank
hard

Fix 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'
A"-122.4194"
B-122.4194
Clatitude
Dnil
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number for longitude.
Using latitude value again instead of longitude.
4fill in blank
hard

Fill 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'
Acoordinate
Btitle
Csubtitle
Dregion
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.
5fill in blank
hard

Fill 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'
A-118.2437
B0.05
D1.0
Attempts:
3 left
💡 Hint
Common Mistakes
Using large span values which zoom out too far.
Using positive longitude for a west coast city.