IOS Swift Baidu Map add multiple annotations

Source: Internet
Author: User
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
        }

}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.