緯度データと経度データをDestinationViewControllerという別のコントローラに渡したいとします。 DestinationViewControllerにはマップビューが含まれているため、ユーザーが新しいビューに移行すると、最初のビューの位置(緯度と経度)データに基づいてフライオーバーマップが表示されます。View Controllerからデータを渡す方法は?
ここで私が途中で説明するいくつかの問題があります。
最初のビュー
import UIKit
import MapKit
import CoreLocation
class SliderViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet weak var slider: UISlider!
private var latitude : [Double]!
private var longtitude : [Double]!
override func viewDidLoad() {
sliderSlides(self)
}
@IBAction func sliderSlides(sender: AnyObject) {
let userChoice = Double(self.slider.value)
var realLatlong = [double]()
if userChoice == 1 {
realLatlong = [40.7484405, -73.9856644]
} else if possibility == 2 {
realLatlong = [42.7484405, -4.9856644]
} else {
realLatlong = [50.7484405, -7.9856644]
}
latitude = [realLatlong[0]]
longitude = [realLatlong[1]]
NO error now, completely fine
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "sendLocationdata") {
var destination: DestinationViewController = segue.destinationViewController
as! DestinationViewController
SIGABART
destination.latitude = latitude
destination.longtitude = longitude
}
}
}
DestinationViewController
import UIKit
import MapKit
import CoreLocation
class DestinationViewController: UIViewController, MKMapViewDelegate {
var latitude : Float!
var longtitude : Float!
let distance: CLLocationDistance = 700
let pitch: CGFloat = 65
let heading = 90.0
var camera = MKMapCamera()
var coordinate: CLLocationCoordinate2D!
@IBOutlet var flyoverView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
coordinate = CLLocationCoordinate2D(latitude: latitude,
longitude: longitude)
No error at all
flyoverView.mapType = .SatelliteFlyover
camera = MKMapCamera(lookingAtCenterCoordinate: coordinate,
fromDistance: distance,
pitch: 0,
heading: 0)
self.flyoverView.camera = camera
// Do any additional setup after loading the view.
}
override func viewDidAppear(animated: Bool) {
let pitchedCamera = MKMapCamera(lookingAtCenterCoordinate: coordinate, fromDistance: distance, pitch: pitch, heading: 0)
let rotatedCamera = MKMapCamera(lookingAtCenterCoordinate: coordinate, fromDistance: distance, pitch: pitch, heading: 180)
UIView.animateWithDuration(5.0, animations: {
self.flyoverView.camera = pitchedCamera
}, completion: {
(Completed: Bool) -> Void in
UIView.animateWithDuration(25.0, delay: 0, options: UIViewAnimationOptions.CurveLinear, animations: {
self.flyoverView.camera = rotatedCamera
}, completion: nil)
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
私を助けてください。もっと情報が必要な場合はコメントを残してください、ありがとう!
フロートではない、私は、2つのエラーを得ました私の新しい編集を見てください。 –
経度と緯度を浮動小数点から倍精度に変更します。次に、sliderSlidesで経度と緯度を設定するときに、単一の値ではなく配列にします。私は私の答えを更新しました – Sam
とにかく@IBAction funcの外でスライダーの値を取得しますか? –