swift 如何设置 Mapbox 地图的间距?

How do you set the pitch of a Mapbox map in swift?

刚开始使用 Mapbox,在设置 mapView 的 pitch/bearing 时遇到问题。有没有类似的东西:

mapView.setPitch = 45

非常感谢任何帮助!

音高是 MGLMapCamera class 的一部分。

以及这个示例片段

/**
 Pitch toward the horizon measured in degrees, with 0 degrees resulting in a
 two-dimensional map.
 */

func togglePitch(sender: UISwitch)  {
    let camera = mapView!.camera
    camera.pitch = sender.on ? 60 : 0
    mapView!.setCamera(camera, animated: false)
}

这是您可以做到的一种方法。

//Create a new MKMapCamera object
var newCameraPosition = MGLMapCamera(lookingAtCenterCoordinate: mapView.centerCoordinate, fromDistance: mapView.camera.altitude + 1600, pitch: 50, heading: -30)

// Then you could call it like this
 mapView.camera = newCameraPosition

MapBox MGLMapCamera

但让我详细说明设置。

@IBOutlet weak var mapView: MGLMapView!

let distance: CLLocationDistance = 500
let pitch: CGFloat = 35
let heading = 45.0
var camera = MGLMapCamera()
let coordinate = CLLocationCoordinate2D(latitude: 49.7484405,
                                        longitude: -132.9856644)

override func viewDidLoad() {
    super.viewDidLoad()
    mapView.mapType = .Standard

    camera = MGLMapCamera(lookingAtCenterCoordinate: coordinate,
                         fromDistance: distance,
                         pitch: 0,
                         heading: 0)
    self.mapView.camera = camera
}