高德地圖大頭針title和subtitle

高德地圖假如你要給大頭針設(shè)置title或者subtitle,像這樣

let pointAnnotation = MAPointAnnotation()
pointAnnotation.coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
pointAnnotation.title = address
pointAnnotation.subtitle = address

但是實(shí)際上是行不通的
所以要在代理方法里面進(jìn)行自定義 ,LNPinAnnotationView是我自定義的繼承于MAPinAnnotationView的一個(gè)類
然后 你可以在這個(gè)自定義類上添加相應(yīng)的label或者其他控件

// 大頭針回調(diào)
    func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! {
        
        if annotation.isKind(of: MAPointAnnotation.self) {
            let pointReuseIndetifier = "pointReuseIndetifier"
            var annotationView: LNPinAnnotationView? = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIndetifier) as! LNPinAnnotationView?
            if annotationView == nil {
                annotationView = LNPinAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIndetifier)
            }
            annotationView?.image = UIImage(named: "MyLocation")
            return annotationView!
        }
        return nil
    }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。