2016-08-17 46 views

回答

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 
} 
+0

這是完美的,謝謝! – SoftwareStudent123

+0

只是好奇。在你的情況下,你是否能夠使用對象實例化,然後可以調用它?或者您是否也需要創建相機對象?附:我已經在幾個MapBox項目上工作過,所以如果你有任何其他問題,我可能會爲你回答它們。 – tymac

+0

我需要創建相機對象。如果你有一些空閒時間,我真的很感激你看看[這個鏈接](http://stackoverflow.com/questions/39050098/need-help-recreating-this-mapbox-effect)。我正在嘗試創建一個適用於健身應用程序的效果。謝謝! – SoftwareStudent123

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