前提・実現したいこと
取得した現在地の値を用いて、計算を行う機能を実装したいです。
発生している問題・エラーメッセージ
現在位置の取得は出来ましたが、他のfuncに緯度・経度を引き渡すことができません。
該当のソースコード
以下は現在位置を取得するコードです。
Swift
1import UIKit 2import CoreLocation 3 4class ViewController: UIViewController, CLLocationManagerDelegate { 5 6 var locationManager: CLLocationManager! 7 8 func setupLocationManager() { 9 locationManager = CLLocationManager() 10 guard let locationManager = locationManager else { return } 11 locationManager.requestWhenInUseAuthorization() 12 13 let status = CLLocationManager.authorizationStatus() 14 if status == .authorizedWhenInUse { 15 locationManager.delegate = self 16 locationManager.distanceFilter = 10 17 locationManager.startUpdatingLocation() 18 } 19 } 20 21 func locationManager(_ manager: CLLocationManager, didUpdateLocations location: [CLLocation]) { 22 let location = location.first 23 let latitude = location?.coordinate.latitude 24 let longitude = location?.coordinate.longitude 25 } 26} 27 28override func viewDidLoad() { 29 super.viewDidLoad() 30 // Do any additional setup after loading the view, typically from a nib. 31 setupLocationManager() 32ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー 33 34この中でlatitudeとlongitudeの値を使用して計算をしたいです。 35 例)let λ:Double = latitude 36 let θ:Double = longitude 37 38 let F:Double = λ +θ 39 40ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー 41 }
補足情報(FW/ツールのバージョンなど)
Swift4.0
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。