【问题标题】:Annotation Map View (Custom Marker ) not working in swift IOS注释地图视图(自定义标记)在 swift IOS 中不起作用
【发布时间】:2018-01-15 11:39:22
【问题描述】:

// 我的视图控制器代码
// AddAnnotation 和 MApView 但我不知道这个问题如果可能的话请上传一个演示代码,因为我是 iOS 新手

private func addAnnotation(coordinate coordinate:CLLocationCoordinate2D, title: String, subtitle: String) {
    let coordinatesss = CLLocationCoordinate2D(latitude: 28.56785, longitude: 78.54255)

    addAnnotation(coordinate: coordinates , title: "titles" , subtitle: "subtitles")

    mapView.addAnnotation(annotation)
}

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
    if annotation is MKUserLocation { return nil }
    let coordinates = CLLocationCoordinate2D(latitude: 28.56785, longitude: 78.54255)

    let identifier = "CustomAnnotation"

    var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)

    if annotationView == nil {
        annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
        annotationView!.canShowCallout = true
        annotationView!.image = UIImage(named: "star.png")!  
    } else {
        annotationView!.annotation = annotation
    }

    return annotationView
}

【问题讨论】:

  • 请显示此代码的更多上下文。

标签: ios swift annotations mapkit


【解决方案1】:

试试下面的代码

override func viewDidLoad() {
    super.viewDidLoad()

    let coordinate = CLLocationCoordinate2D(latitude: 28.56785, longitude: 78.54255)
    let annotation = MKPointAnnotation()
    annotation.coordinate = coordinate
    annotation.title = "titles"
    annotation.subtitle = "subtitles"
    self.mapView.addAnnotation(annotation)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多