Graeme K
Graeme K

Reputation: 89

MKMapCamera showing south

is there a way to load mapKit facing south instead of north in swift 2?

I have tried MKMapCamera and looked at apple documentation but nothing I have read or tried is working.

Thanks in advance.

Upvotes: 2

Views: 158

Answers (1)

Jeffrey Morgan
Jeffrey Morgan

Reputation: 566

The following Swift code creates an MKMapCamera object with a heading of 180°, which orients the map to face South:

let camera = MKMapCamera()
camera.centerCoordinate = CLLocationCoordinate2D(latitude: 48.858, longitude: 2.294)
camera.heading = 180.0
mapView.setCamera(camera, animated: true)

The heading property of an MKMapCamera controls the compass angle the map will face. 0° is North, 45° is North East, 90° is East, and so on.

If you have a view controller with an IB outlet to an MKMapView object, you can add the above code to the viewDidLoad method:

override func viewDidLoad() {
    super.viewDidLoad()
    let camera = MKMapCamera()
    camera.centerCoordinate = CLLocationCoordinate2D(latitude: 48.858, longitude: 2.294)
    camera.heading = 180.0
    mapView.setCamera(camera, animated: true)
}

Upvotes: 2

Related Questions