地理院の地図をmapViewに表示したいが、参考になるサイトを教えてください。
ios標準の地図を表示することは出来ています。
地図アプリでよくあるような、地図を切り替えて表示するアプリを作りたいと思って調べています。
自分でも、ググって見ましたがよくわかりませんでした。
表示したいのは地理院の「標準図」と「陰影起伏図」です。
初心者の私には高度なことをしようとしているのかもしれませんが、参考になるサイト等を教えてください。
お願いします。
###ソース全文
// MemoViewController.swift // Wood volume // // Created by MBP13 on 2019/05/09. // Copyright © 2019 Tomoyuki Ashikari. All rights reserved. // import UIKit import MapKit import CoreLocation class MemoViewController: UIViewController ,UIImagePickerControllerDelegate,UINavigationControllerDelegate,CLLocationManagerDelegate,UIGestureRecognizerDelegate { @IBOutlet weak var mapTypeLabel: UILabel! @IBOutlet weak var saveButton: UIBarButtonItem! var locationManager:CLLocationManager! var memo: String?//saveボタン用 @IBOutlet weak var memoTextField: UITextField! @IBOutlet weak var map: MKMapView! @IBOutlet weak var latiudeLabel: UILabel! @IBOutlet weak var longitudeLabel: UILabel! @IBOutlet weak var satelliteLabel: UILabel! @IBOutlet weak var dopLabel: UILabel! @IBOutlet weak var measureButton: UIButton! let width = UIScreen.main.bounds.size.width//画面の幅 let height = UIScreen.main.bounds.size.height//画面の高さ var cnt : Int = 0 //表示領域を指定:はじめの1回だけ現在地をセンターにするためif cntを設置 @IBAction func measureButton(_ sender: Any) { print("開始") } // 画面の切替 @objc func mapViewTypeBtnThouchDown(_ sender: Any) { switch map.mapType { case .satelliteFlyover: // 地図よりもデータを強調○ map.mapType = .standard mapTypeLabel.text = "standard" mapTypeLabel.frame = CGRect(x:10, y: 130, width:90, height:30) print("standard") break case .standard: // 3D航空写真☓ map.mapType = .satelliteFlyover mapTypeLabel.text = "3D" mapTypeLabel.frame = CGRect(x:10, y: 130, width:33, height:30) print("satelliteFlyover") break @unknown default: break } } override func viewDidLoad() { super.viewDidLoad() locationManager = CLLocationManager() locationManager.desiredAccuracy = kCLLocationAccuracyBest //最高精度 locationManager.activityType = .fitness//歩行者other その他(デフォルト値) locationManager.requestAlwaysAuthorization() locationManager.delegate = self // CLLocationManagerDelegat locationManager.startUpdatingLocation()//観測開始 [CLLocation]) { (location.timestamp.description)") (location.coordinate.longitude) 取得時刻:(location.timestamp.description)") self.navigationItem.title = "Edit Memo" if let memo = self.memo{ self.memoTextField.text = memo } self.updateSaveButtonState() // Do any additional setup after loading the view, typically from a nib. // 地図の設定〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜 map.mapType = MKMapType.satelliteFlyover//マップタイプ切替 print("satelliteFlyover") map.userTrackingMode = .follow//トラッキングモード // 地図表示タイプを切り替えるボタンを配置する var mapViewType: UIButton! mapViewType = UIButton(type: UIButton.ButtonType.detailDisclosure) /////////////////////////////////////////////////////////////////// mapViewType.frame = CGRect(x:10, y: 165, width:33, height:30) mapViewType.layer.backgroundColor = UIColor(white: 1, alpha: 0.65).cgColor // 背景色 mapViewType.layer.borderWidth = 0.5 // 枠線の幅 mapViewType.layer.borderColor = UIColor.blue.cgColor // 枠線の色 self.view.addSubview(mapViewType) //////////////////////////////////////////////////////////////////// mapTypeLabel.frame = CGRect(x:10, y: 130 , width:33, height:30) mapTypeLabel.layer.backgroundColor = UIColor(white: 1, alpha: 0.8).cgColor // 背景色 mapTypeLabel.layer.borderWidth = 0.5 // 枠線の幅 mapTypeLabel.layer.borderColor = UIColor.blue.cgColor // 枠線の色 self.view.addSubview(mapTypeLabel) mapTypeLabel.text = "3D" // 地図の表示タイプを切り替える関数 mapViewType.addTarget(self, action: #selector(mapViewTypeBtnThouchDown(_:)), for: .touchDown) print("map幅(map.bounds.size.width)") print("map高さ(map.bounds.size.height)") print("map座標左端(map.frame.origin.x)") // 右端 view.frame.origin.x + view.frame.size.width print("map座標上端(map.frame.origin.y)") // 下端 view.frame.origin.y + view.frame.size.height } private func updateSaveButtonState(){ let memo = self.memoTextField.text ?? "" //memoがnilだったら空文字 self.saveButton.isEnabled = !memo.isEmpty //saveButtonnが有効なのはsaveButtonが空でないとき } @IBAction func memoTextFieldChanged(_ sender: Any) { updateSaveButtonState() } @IBAction func cancel(_ sender: Any) { if self.presentingViewController is UINavigationController { self.dismiss(animated: true, completion: nil) } else { self.navigationController?.popViewController(animated: true) } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } //saveボタンが押されたときの処理だったらsenderに入ってくるのでguardでチェック //ボタンアイテムでキャストする //saveボタンと同じか比較する //そうじゃなかったらreturnでとめる //これでセグエが巻き戻る時に値がセットされる override func prepare(for segue: UIStoryboardSegue, sender: Any?) { guard let button = sender as? UIBarButtonItem, button === self.saveButton else { return } self.memo = self.memoTextField.text ?? "" } } //位置情報の許可=========================================== extension MemoViewController { func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { switch status { case .notDetermined: print("ユーザーはこのアプリケーションに関してまだ選択を行っていません") locationManager.requestAlwaysAuthorization() // 常に許可 break case .denied: print("ローケーションサービスの設定が「無効」になっています (ユーザーによって、明示的に拒否されています)") // アラート生成 let alert : UIAlertController = UIAlertController(title: "測定を続けるには", message: "設定 > プライバシー > 位置情報サービス で、位置情報サービスの利用を許可して下さい。", preferredStyle: .alert) // OKボタンを追加 let okAction = UIAlertAction(title:"OK", style: .default,handler: nil) alert.addAction(okAction) // 表示 present(alert,animated: true,completion: nil) break case .restricted: print("このアプリケーションは位置情報サービスを使用できません(ユーザによって拒否されたわけではありません)") // 「このアプリは、位置情報を取得できないために、正常に動作できません」を表示する break case .authorizedAlways: print("常時、位置情報の取得が許可されています。") // 位置情報取得の開始処理 break case .authorizedWhenInUse: print("起動時のみ、位置情報の取得が許可されています。") // 位置情報取得の開始処理 locationManager.requestAlwaysAuthorization() // 常に許可 break @unknown default: break } } //===========================================位置情報の許可 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {//GPSが更新すると呼ばれる let location : CLLocation = locations[0] let currentlocation = location.coordinate //表示領域を指定:はじめの1回だけ現在地をセンターにするためif cntを設置 if cnt == 0{ let reg : MKCoordinateRegion = MKCoordinateRegion(center: currentlocation,latitudinalMeters: 100,longitudinalMeters: 100) //アノテーションを生成し、表示 // let ann : MKPointAnnotation = MKPointAnnotation() map.region = reg //ann.title = "現在地" //map.addAnnotation(ann) //仮想カメラの位置 let viewPoint :CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude-0.005, location.coordinate.longitude) //ビルを見せる map.showsBuildings = true //拡大縮小 map.isPitchEnabled = true //3D用の仮想カメラオブジェクトを500m上空にセット let cameraVR : MKMapCamera = MKMapCamera(lookingAtCenter: currentlocation, fromEyeCoordinate: viewPoint, eyeAltitude: 100) map.camera = cameraVR cnt = 1 } latiudeLabel.text = String("緯度:(location.coordinate.latitude)" ) longitudeLabel.text = String("経度:(location.coordinate.longitude)") satelliteLabel.text = String("horizontalAccuracyは(location.horizontalAccuracy)") dopLabel.text = String("verticalAccuracyは(location.verticalAccuracy)") } }
あなたの回答
tips
プレビュー