如何在swift中设置Mapbox地图的音高?

时间:2016-08-17 18:41:30

标签: ios swift maps mapbox mapbox-gl

使用Mapbox非常新,并且在设置mapView的音高/方位时遇到了麻烦。是否有类似的东西:

mapView.setPitch = 45

非常感谢任何帮助!

2 个答案:

答案 0 :(得分:1)

音高是MGLMapCamera类的一部分。

此示例代码段

/**
 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)
}

答案 1 :(得分:1)

这是你可以做到的一种方式。

//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
}