SoftwareStudent123 SoftwareStudent123 - 2 months ago 23x
iOS Question

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

Very new to using Mapbox, and having troubles setting the pitch/bearing of the mapView. Is there something like:

mapView.setPitch = 45

Any help is greatly appreciated!


This is one way you can do it.

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

// Then you could call it like this = newCameraPosition

MapBox MGLMapCamera

But let me elaborate for the setup.

@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() {
    mapView.mapType = .Standard

    camera = MGLMapCamera(lookingAtCenterCoordinate: coordinate,
                         fromDistance: distance,
                         pitch: 0,
                         heading: 0) = camera