[ios] 지도에 사용자 지정 핀 표시하기

사용자 지정 핀 추가하기

보통 지도에 사용자 지정 핀을 추가하기 위해서는 MKMapView를 이용하여 특정 위치에 핀을 추가하고 해당 위치를 표시합니다.

import MapKit

class MapViewController: UIViewController, MKMapViewDelegate {
    @IBOutlet weak var mapView: MKMapView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 사용자 지정 핀 생성
        let annotation = MKPointAnnotation()
        annotation.title = "위치 제목"
        annotation.coordinate = CLLocationCoordinate2D(latitude: 37.7, longitude: -122.4)
        
        // 지도에 핀 추가
        mapView.addAnnotation(annotation)
    }
    
    // 핀 모양 및 색상 지정
    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        let identifier = "CustomPinAnnotationView"
        var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
        
        if annotationView == nil {
            annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
            annotationView?.canShowCallout = true
        } else {
            annotationView?.annotation = annotation
        }
        
        return annotationView
    }
}

위 예시는 iOS 앱에서 사용자 지정 핀을 추가하고 지도에 표시하는 방법을 보여줍니다.

결론

위의 예시 코드를 따라하면 iOS 애플리케이션에서 지도에 사용자 지정 핀을 표시할 수 있습니다. 이를 통해 지도 애플리케이션에 더 많은 기능을 추가할 수 있을 것입니다. 만약 추가적인 도움이 필요하다면 저와 함께 상세히 알아보세요!