아미(아름다운미소)
swift 맵 뷰로 지도 나타내기1(Map Kit View 추가) 본문
- Map Kit View 추가 후 아웃렛 변수 설정
위치 |
class ViewController 최상단 |
연결(Connection) |
Outlet |
이름(Name) |
myMap |
유형(Type) |
MKMapView |
import MapKit
@IBOutlet weak var myMap: MKMapView!
- Info.plist(수정) : 앱이 사용자 위치에 접근하도록 허용하기
import UIKit
import MapKit
class ViewController: UIViewController, CLLocationManagerDelegate{
@IBOutlet weak var myMap: MKMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
//상수 locationManager의 델리게이트를 self로 설정합니다.
locationManager.delegate = self
//정확도를 최고로 설정합니다.
locationManager.desiredAccuracy = kCLLocationAccuracyBest
//위치 데이터를 추적하기 위해 사용자에게 승인을 요구합니다.
locationManager.requestWhenInUseAuthorization()
//위치 업데이트를 시작합니다.
locationManager.startUpdatingLocation()
//위치보기 값을 true로 설정합니다.
myMap.showsUserLocation = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
[결과화면] 스토리보드 실행화면
'랭귀지 > SWIFT' 카테고리의 다른 글
swift 맵 뷰로 지도 나타내기3(위치 정보를 추출해서 텍스트로 표시하기) (0) | 2018.02.01 |
---|---|
swift 맵 뷰로 지도 나타내기2(위도와 경도로 원하는 위치 표시하기) (0) | 2018.01.31 |
'http://' 문자열 자동 삽입 (0) | 2018.01.29 |
swift [File] 버튼 구현하기 (0) | 2018.01.28 |
swift [html] 버튼 구현하기 (0) | 2018.01.27 |