맵에서 각 위치에 있는 장소에 대한 정보를 핀으로 표시하게 되는 것을 의미 합니다
여기서 할 것은 핀 + 각 정보에 대한 이름을 표시하는 것입니다
import MapKit
class stopInfo: NSObject, MKAnnotation {
let name : String?
let coordinate : CLLocationCoordinate2D
let title: String? // 어노테이션 이름
init(name: String?coordinate: CLLocationCoordinate2D) {
self.name = name
self.coordinate = coordinate
self.title = name // 어노테이션 이름 나오게 함
super.init()
}
var subtitle: String? { // 클릭하면 어노테이션 나오게 함
return name
}
}
위와 같이 어노테이션을 할 정보를 넣을 클래스를 만들어 줍니다
let annot = stopInfo(title: "이름", coordinate: CLLocationCoordinate2D(latitude: ~~, longitude: ~~))
mapView.addAnnotation(annot)
위와 같이 하면 실행이 됩니다
핀을 클릭하면 subtitle 이 title 아래 뜨게 됩니다
주의해야 할 점은 정보를 담은 클래스에
title 과 subtitle 이 필요합니다
있어야 핀에 대한 제목, 부제목이 뜹니다