Engaged in a day to add a number of annotations to make, and a profound response to write code blindly copy, I do not know its consequences are too serious, a bit of a mistake to find a big half-day, OK, but more BB, said add a number of annotations to pay attention to some things.
First of all, the method of adding a pin to achieve after _mapview.delegate = self, otherwise add a pin too early, and will not invoke Bmkmapviewdelegate proxy method to refresh Mapview
Second, add Pin method, bmkpointannotation initialization must be placed in the loop, otherwise pointannotation although will be added three times, but these three pointannotation are the same object, and finally draw the pin will only have a
Add pin
func addpointannotation () {
if (pointannotation = = nil) {let
ary1:nsarray = ["31.222771", " 39.915 "," 31.229003 "] let
ary2:nsarray = [" 121.490317 "," 116.404 "," 121.448224 "]
var coor: Cllocationcoordinate2d = Cllocationcoordinate2d.init () for
(Var i=0;i<ary1.count;i++) {
pointannotation = Bmkpointannotation.init ()//must be placed in the loop to initialize
coor.latitude = ary1[i].doublevalue
coor.longitude = ary2[i]. Doublevalue
pointannotation.coordinate = coor
pointannotation.title = "Ha"
_mapview.addannotation ( pointannotation)
}}}
Finally, Bmkmapviewdelegate draws the view
Generate the corresponding view
func Mapview (mapview:bmkmapview!, viewforannotation annotation:bmkannotation!) according to Anntation-> bmkannotationview! {
// //annotation let
annotationviewid = "Renamemark"
var annotationview:bmkpinannotationview? = _ Mapview.dequeuereusableannotationviewwithidentifier (Annotationviewid) as? Bmkpinannotationview
if (Annotationview = = nil) {
Annotationview = bmkpinannotationview.init (annotation: annotation, reuseidentifier:annotationviewid)
}
//Set color
// Annotationview? Pincolor = bmkpinannotationcolorpurple
//fall from the sky effect
annotationview!. Animatesdrop = True
//settings do not drag
annotationview!. Draggable = False
annotationview!. Image = UIImage (named: "Sina") return
Annotationview
}
}