macOS12.4 Xcode13.0 を使用
現在位置を取得して地図に表示するために、以下のように書きました。(一部略)
Swift
1import UIKit 2import MapKit 3import CoreLocation 4 5class ViewController!: UIViewController ,MKMapViewDelegate, 6 CLLocationManagerDelegate{ 7 var locationManager = CLLocationManager() 8 9 override func viewDidLoad() { 10 super.viewDidLoad() 11 12 // Do any additional setup after loading the view. 13 locationManager.delegate = self 14 } 15 16 17 override func viewDidAppear(_ animated: Bool) { 18 19 20 //位置情報サービスの確認 21 CLLocationManager.locationServicesEnabled() 22 23 // セキュリティ認証のステータス 24 let manager = CLLocationManager() 25 //let status = CLLocationManager.authorizationStatus() 26 let status = manager.authorizationStatus 27 28 if(status == CLAuthorizationStatus.notDetermined) { 29 print("NotDetermined") 30 // 許可をリクエスト 31 locationManager.requestWhenInUseAuthorization() 32 33 } 34 else if(status == CLAuthorizationStatus.restricted){ 35 print("Restricted") 36 } 37 else if(status == CLAuthorizationStatus.authorizedWhenInUse){ 38 print("authorizedWhenInUse") 39 } 40 else if(status == CLAuthorizationStatus.authorizedAlways){ 41 print("authorizedAlways") 42 } 43 else{ 44 print("not allowed") 45 } 46 47 // 位置情報の更新 48 locationManager.startUpdatingLocation() 49 50 // MapViewのインスタンス生成. 51 let mapView = MKMapView() 52 53 // MapViewをSafeAreaに収める(Portraitのケース) 54 // 以降、Landscape のみを想定 55 let screenWidth = view.frame.size.width 56 let screenHeight = view.frame.size.height 57 58 let rect = CGRect(x: 0, 59 y: 0, 60 width: screenWidth 61 height: screenHeight ) 62 63 mapView.frame = rect 64 65 // Delegateを設定. 66 mapView.delegate = self 67 68 // 縮尺を設定 69 var region:MKCoordinateRegion = mapView.region 70 region.center = mapView.userLocation.coordinate 71 72 region.span.latitudeDelta = 0.02 73 region.span.longitudeDelta = 0.02 74 75 mapView.setRegion(region,animated:true) 76 // MapViewをViewに追加. 77 self.view.addSubview(mapView) 78 79 mapView.mapType = MKMapType.hybrid 80 81 mapView.userTrackingMode = MKUserTrackingMode.follow 82 mapView.userTrackingMode = MKUserTrackingMode.followWithHeading 83 } 84 85 func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) { 86 print("region changed") 87 } 88 89} 90
この状態でシミュレーターでビルドすると、画面には何も表示されず、以下のようなメッセージが出ました。
調べてみると、Info.pliset に原因があるらしいのですが、どこを修正すれば良いのか分かりませんでした。
どのように修正したらよいか教えていただきたいです。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/06/28 01:22