高德地圖假如你要給大頭針設(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
}