###前提・実現したいこと
お世話になります。
iOSアプリ開発を始めて1ヶ月半の初心者です。
現在位置情報を利用するアプリの開発を行っているのですが、
取得した緯度と経度の座標値をラベルに反映できず困っております。
また、Firebaseにデータを送る際に、
逆ジオコーディングのコードの箇所でエラーが生じてしまいます。
これはどのように解決すればよろしいのでしょうか?
ご存知の方がいらっしゃいましたら、
ご助力いただけると幸いです。
よろしくお願い致します。
###該当のソースコード
①緯度・軽度ラベルが更新されない
swift
1override func viewWillAppear(_ animated: Bool) { 2 super.viewWillAppear(animated) 3 4 catchLocationData() 5 6 } 7 8 9//現在地を取得 10func catchLocationData(){ 11 12 if CLLocationManager.locationServicesEnabled() { 13 14 locationManager = CLLocationManager() 15 locationManager.delegate = self 16 locationManager.startUpdatingLocation() 17 18 } 19 } 20 21//位置情報取得に関するアラート 22func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { 23 switch status { 24 case .notDetermined: 25 locationManager.requestWhenInUseAuthorization() 26 case .restricted, .denied: 27 break 28 case .authorizedAlways, .authorizedWhenInUse: 29 break 30 } 31 } 32 33//位置情報が更新されるたびに呼ばれる 34func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 35 guard let newLocation = locations.last else { 36 return 37 } 38 39 self.latitudeLabel.text = "".appendingFormat("%.4f", newLocation.coordinate.latitude) 40 self.longitudeLabel.text = "".appendingFormat("%.4f", newLocation.coordinate.longitude) 41 nowLatitude = newLocation.coordinate.latitude 42 nowLongitude = newLocation.coordinate.latitude 43 44 //↓緯度・軽度ラベルが更新されない↓// 45 self.reverseGeocode(latitude: Double(latitudeLabel.text!)!, longitude: Double(longitudeLabel.text!)!) 46 47 } 48 49// 逆ジオコーディング処理(緯度・経度を住所に変換) 50func reverseGeocode(latitude:CLLocationDegrees, longitude:CLLocationDegrees) { 51 let location = CLLocation(latitude: latitude, longitude: longitude) 52 let geocoder = CLGeocoder() 53 54 geocoder.reverseGeocodeLocation(location, completionHandler: { (placemark, error) -> Void in 55 let placeMark = placemark?.first 56 if let country = placeMark?.country { 57 58 59 print("(country)") 60 61 self.country = country 62 } 63 if let administrativeArea = placeMark?.administrativeArea { 64 print("(administrativeArea)") 65 66 self.administrativeArea = administrativeArea 67 } 68 //以下省略//
②Firebaseに逆ジオコーディングを送る際にエラーが出る
swift
1//Firebaseのストレージへデータを送る 2 func postRoom(){ 3 4 AppDelegate.instance().showIndicator() 5 uid = (Auth.auth().currentUser?.uid)! 6 7 //↓ここでエラーが起こる↓// 8 reverseGeocode(latitude: Double(latitudeLabel.text!)!, longitude: Double(longitudeLabel.text!)!) 9 10 let ref = Database.database().reference() 11 12 //以下省略//
###発生している問題・エラーメッセージ
②のエラー箇所に以下のようなメッセージが表示される。
swift
1Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
###補足情報(言語/FW/ツール等のバージョンなど)
開発環境は以下の通りです。
macOS Sierra(10.12.6)
iOS 11.0
Xcode 9.0
Swift 4.0
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。