ios - Swift: How to enable and disable annotations on map view? -


i have code displays annotations on map view. however, i'm trying have function can enabled or disabled when user taps uiswitch button. suggestions on how can achieve this? in advance!

 let thehouse = mkpointannotation()         thehouse.coordinate = cllocationcoordinate2d(latitude: 38.8977, longitude: -77.0365)      thehouse.title = "the house, dc"         thehouse.subtitle = "new jersey, dc"      mymapview.addannotation(thehouse)     myannotations.append(thehouse.title!)      //switch toggles annotation...     @ibaction func turnoffannotations(_ sender: uiswitch) {     //code enables , disables annotation?  if toggle.ison{     let visible = mymapview.visiblemaprect     let inrect = mymapview.annotations(in: visible)      annotation: mkannotation in mymapview.annotations{         if (inrect.contains(anno as! anyhashable)){           mymapview.removeannotation(annotation)         }     }     } else {         let visible = mymapview.visiblemaprect         let inrect = mymapview.annotations(in: visible)          annotation: mkannotation in mymapview.annotations{             if (inrect.contains(anno as! anyhashable)){                 mymapview.addannotation(annotation)             }         }     } //how add removed annotations here?...     } 

use viewfor(annotation : mkannotation) method :

swift 3

@ibaction func changeannotationsvisibility(_ sender: uiswitch) {     let annotationvisible = sender.ison      annotation in mymapview.annotations {         mymapview.view(for: annotation)?.ishidden = !annotationvisible     } } 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -