macOS12.4 Xcode13.0 を使用
現在位置を取得して地図に表示するために、以下のように書きました。(一部略)
Swift
import UIKit import MapKit import CoreLocation class ViewController!: UIViewController ,MKMapViewDelegate, CLLocationManagerDelegate{ var locationManager = CLLocationManager() override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. locationManager.delegate = self } override func viewDidAppear(_ animated: Bool) { //位置情報サービスの確認 CLLocationManager.locationServicesEnabled() // セキュリティ認証のステータス let manager = CLLocationManager() //let status = CLLocationManager.authorizationStatus() let status = manager.authorizationStatus if(status == CLAuthorizationStatus.notDetermined) { print("NotDetermined") // 許可をリクエスト locationManager.requestWhenInUseAuthorization() } else if(status == CLAuthorizationStatus.restricted){ print("Restricted") } else if(status == CLAuthorizationStatus.authorizedWhenInUse){ print("authorizedWhenInUse") } else if(status == CLAuthorizationStatus.authorizedAlways){ print("authorizedAlways") } else{ print("not allowed") } // 位置情報の更新 locationManager.startUpdatingLocation() // MapViewのインスタンス生成. let mapView = MKMapView() // MapViewをSafeAreaに収める(Portraitのケース) // 以降、Landscape のみを想定 let screenWidth = view.frame.size.width let screenHeight = view.frame.size.height let rect = CGRect(x: 0, y: 0, width: screenWidth height: screenHeight ) mapView.frame = rect // Delegateを設定. mapView.delegate = self // 縮尺を設定 var region:MKCoordinateRegion = mapView.region region.center = mapView.userLocation.coordinate region.span.latitudeDelta = 0.02 region.span.longitudeDelta = 0.02 mapView.setRegion(region,animated:true) // MapViewをViewに追加. self.view.addSubview(mapView) mapView.mapType = MKMapType.hybrid mapView.userTrackingMode = MKUserTrackingMode.follow mapView.userTrackingMode = MKUserTrackingMode.followWithHeading } func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) { print("region changed") } }
この状態でシミュレーターでビルドすると、画面には何も表示されず、以下のようなメッセージが出ました。
調べてみると、Info.pliset に原因があるらしいのですが、どこを修正すれば良いのか分かりませんでした。
どのように修正したらよいか教えていただきたいです。
まだ回答がついていません
会員登録して回答してみよう