xcode 上的 MapKit 相机使用 swift?

MapKit camera on xcode using swift?

我从 获得了以下代码,但我不确定如何处理它。我希望我的地图呈 45 度角,有点像当您使用地图应用程序并使用 2 根手指向上拖动时,我希望我的相机始终保持这种角度。

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)

首先我们需要导入MapKit。

import MapKit

然后在class中我们需要合并MKMapViewDelegate协议并制作MapView对象,并设置属性来制作你想要的。

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)

           ...

       }

    ...
 }

希望对您有所帮助!