swift - Show/Hide annotation when button is pressed -


what want achieve when pressed button annotation show , hide if pressed button again. far show annotation repeatedly.

here code.

@ibaction func showannotation(sender: anyobject) {     addattractionpins() }  func addattractionpins() {     let filepath = nsbundle.mainbundle().pathforresource("attractions", oftype: "plist")     let attractions = nsarray(contentsoffile: filepath!)     attraction in attractions! {         let point = cgpointfromstring(attraction["location"] as! string)         let coordinate = cllocationcoordinate2dmake(cllocationdegrees(point.x), cllocationdegrees(point.y))         let title = attraction["name"] as! string         let typerawvalue = (attraction["type"] as! string).toint()!         let type = attractiontype(rawvalue: typerawvalue)!         let subtitle = attraction["subtitle"] as! string         let annotation = attractionannotation(coordinate: coordinate, title: title, subtitle: subtitle, type: type)         mapview.addannotation(annotation)     } } 

use code add , remove annotation:

var annotationisvisible = false  @ibaction func showannotation(sender: anyobject) {     if !annotationisvisible {         addattractionpins()         annotationisvisible = true      }else {         map.removeannotations(map.annotations)         annotationisvisible = false     }  }  func addattractionpins() {      let filepath = nsbundle.mainbundle().pathforresource("attractions", oftype: "plist")     let attractions = nsarray(contentsoffile: filepath!)     attraction in attractions! {         let point = cgpointfromstring(attraction["location"] as! string)         let coordinate = cllocationcoordinate2dmake(cllocationdegrees(point.x), cllocationdegrees(point.y))         let title = attraction["name"] as! string         let typerawvalue = (attraction["type"] as! string).toint()!         let type = attractiontype(rawvalue: typerawvalue)!         let subtitle = attraction["subtitle"] as! string         let annotation = attractionannotation(coordinate: coordinate, title: title, subtitle: subtitle, type: type)         mapview.addannotation(annotation)     } } 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -