今、GoogleMapsで現在地を取得するiosアプリを開発しています。
以下のエラーが解決できません。
▪️エラー箇所
self.mapView.camera = camera
▪️エラー内容
「Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value」
どなたか、ヒントをいただければ幸いです。
※outlet接続はできているようでした。
import UIKit import GoogleMaps class ViewController: UIViewController,CLLocationManagerDelegate { let locationManager = CLLocationManager() @IBOutlet weak var mapView: GMSMapView! override func viewDidLoad() { super.viewDidLoad() setupLocationManager() let camera = GMSCameraPosition.camera(withLatitude: 35.6875364, longitude: 139.7013586, zoom: 15.0) エラー箇所→ self.mapView.camera = camera // 追加箇所 // markerはピンの場所 let marker = GMSMarker() marker.position = CLLocationCoordinate2D(latitude: 35.6875364, longitude: 139.7013586) marker.title = "新宿" marker.snippet = "新宿" marker.map = mapView // ユーザーに対して位置情報を取得する許可をリクエストする func setupLocationManager() { locationManager.requestWhenInUseAuthorization() } func setupLocationManager() { locationManager.requestWhenInUseAuthorization() // ↓NEW if .authorizedWhenInUse == CLLocationManager.authorizationStatus() { // 何メートル移動ごとに情報を取得するか。ここで設定した距離分移動したときに現在地を示すマーカーも移動する locationManager.distanceFilter = 1 // 位置情報取得開始 locationManager.startUpdatingLocation() } } // 位置情報を取得・更新するたびに呼ばれる ← NEW func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { print(locations) } }
あなたの回答
tips
プレビュー