Mapview Swift的自定义注释

问题描述

我查看了相关信息,但仍未收到自定义图钉...。

自定义注释->包括设置我的图片

 import UIKit
 import MapKit

 class CustomPointAnnotation: MKPointAnnotation {
     var pinCustomImageName: UIImage!
 }

视图控制器:

我想返回当前位置,直到选择了一个按钮以放置图钉

func mapView(_ mapView: MKMapView,viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    //current Location
    if !(annotation is CustomPointAnnotation) {
        return nil
    }
    let reuseIdentifier = "pin"
    var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseIdentifier)
    if annotationView == nil {
        annotationView = MKAnnotationView(annotation: annotation,reuseIdentifier: reuseIdentifier)
        annotationView!.canShowCallout = true
        
    } else {
        annotationView!.annotation = annotation
    }
    if let annotationView = annotationView {
        annotationView.image = UIImage(named: "Skyscraper")
        annotationView.canShowCallout = true
    }
   
    return annotationView
}

func addPin() {
    pointAnnotation = CustomPointAnnotation()
    pointAnnotation.pinCustomImageName = UIImage(named: "Skyscraper")
    pointAnnotation.coordinate = currentLocation.coordinate
    pointAnnotation.title = "First Building"
    pointAnnotation.subtitle = "Latitude: \(currentLocation.coordinate.latitude),\ 
     (currentLocation.coordinate.longitude)"
    mapView.addAnnotation(pointAnnotation)
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)