2

I got the following code from Tilt map in Mapkit programmatically using Swift but I'm not sure what to do with it. I want my map to be in like a 45 degree angle, kind of like when you use the maps app and you drag up using 2 fingers, I want my camera to always be that way.

let userCoordinate = CLLocationCoordinate2D(latitude: 58.592725, longitude: 16.185962)
let eyeCoordinate = CLLocationCoordinate2D(latitude: 58.571647, longitude: 16.234660)
let mapCamera = MKMapCamera(lookingAtCenterCoordinate: userCoordinate, fromEyeCoordinate: eyeCoordinate, eyeAltitude: 400.0)
Community
  • 1
  • 1
Amissi
  • 167
  • 2
  • 12

1 Answers1

3

First we need to import MapKit.

import MapKit

Then in the class we need to incorporate the MKMapViewDelegate protocol and make the MapView object, and set the attributes to make what you desire.

class ExampleClassController: MKMapViewDelegate {
   @IBOutlet weak var mapView: MKMapView!

       override func viewDidLoad() {
           super.viewDidLoad()

           let userCoordinate = CLLocationCoordinate2D(latitude: 58.592725, longitude: 16.185962)
           let eyeCoordinate = CLLocationCoordinate2D(latitude: 58.571647, longitude: 16.234660)
           let mapCamera = MKMapCamera(lookingAtCenterCoordinate: userCoordinate, fromEyeCoordinate: eyeCoordinate, eyeAltitude: 400.0)
           let annotation = MKPointAnnotation()
           annotation.setCoordinate(userCoordinate)

           //Setup our Map View
           mapView.delegate = self
           mapView.mapType = MKMapType.Standard
           mapView.addAnnotation(annotation)
           mapView.setCamera(mapCamera, animated: true)

           ...

       }

    ...
 }

Hope that helps!

The Brofessor
  • 1,008
  • 6
  • 15