2017-01-05 3 views
0

하나의 주석이 포함 된지도를 만들었습니다. 내가 본 것에서 이것은 매우 간단한 방법으로이 튜토리얼에서 벗어났다. 나는 현재 주석으로 맞춤 사진을 얻으려고 애 쓰고 있지만이 주제에 관한 거의 모든 정보가 객관적이다. 용서하기가 정말로 쉽다면 나에게 용서해라. 그러나 나는 상대적으로 코딩에 익숙하지 않고 어떤 것에도 감사 할 것이다. 도움 :)사용자 지정 주석 Swift

class ViewController2: UIViewController { 
@IBOutlet var Map: MKMapView! 

override func viewDidLoad() { 
super.viewDidLoad() 
// Do any additional setup after loading the view, typically from a nib. 

//Location for first Pin 
let locationOne = CLLocationCoordinate2DMake(-47.016945, 167.852095) 

//Location for map centering 
let locationNZ = CLLocationCoordinate2DMake(-43.937462, 170.507813) 
let span = MKCoordinateSpanMake(9, 9) 
let region = MKCoordinateRegion(center: locationNZ, span: span) 
Map.setRegion(region, animated: true) 

//Create annotation one 
let annotation = MKPointAnnotation() 
annotation.coordinate = locationOne 
annotation.subtitle = "Park" 
annotation.title = "Rakiura National Park" 

//Add annotation to the map 
Map.addAnnotation(annotation)} 

답변

0

원하는 기본 핀과 다른 이미지가 있다고 가정합니까? 내가 다른 질문에서이 대답을 사용했습니다, 여기 Custom pin image in annotationView in iOS

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { 
// Don't want to show a custom image if the annotation is the user's location. 
guard !annotation.isKindOfClass(MKUserLocation) else { 
    return nil 
} 

let annotationIdentifier = "AnnotationIdentifier" 

var annotationView: MKAnnotationView? 
if let dequeuedAnnotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(annotationIdentifier) { 
    annotationView = dequeuedAnnotationView 
    annotationView?.annotation = annotation 
} 
else { 
    let av = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier) 
    av.rightCalloutAccessoryView = UIButton(type: .DetailDisclosure) 
    annotationView = av 
} 

if let annotationView = annotationView { 
    // Configure your annotation view here 
    annotationView.canShowCallout = true 
    annotationView.image = UIImage(named: "yourImage") 
} 

return annotationView 
} 
+0

죄송합니다 그것을 확인하지만 난 엑스 코드에 최선을하지 오전이 질문에 코드를 구현하는 방법에 대한 질문이 있습니다. 나는 닫는 괄호 앞에 클래스의 끝 부분에 놓았지만 함수는 결코 사용되지 않습니다. 잘못된 위치에 있습니까? 아니면 전화해야합니까? 다시 한 번 내 무지를 유감스럽게 생각합니다. – Nick0014

+0

안녕하세요. 코드가 어떻게 보이는지 질문을 편집 해 볼 수 있습니까? – jonask

관련 문제