Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding map annotations without deleting them

Using a MKMapView I have a pile of annoatations loaded onto it and I want to be able to filter the annotations displayed with a segmented control.

I'm using custom annotations with a type variable so I can tell them apart from one another but I haven't been able to find a way to hide and display a subset of annotation views at will.

like image 806
Affian Avatar asked Feb 09 '10 23:02

Affian


1 Answers

Sure, try this:

Objective-C solution:

[[yourMapView viewForAnnotation:yourAnnotation] setHidden:YES]

Swift 4 solution:

yourMapView.view(for: yourAnnotation)?.isHidden = true

This will return you the view associated with the specified annotation object, then you can set the view to hidden. Here is the documentation.

like image 115
Ryan Ferretti Avatar answered Sep 28 '22 01:09

Ryan Ferretti