Reload or Refresh the MKMapView based on the different preferences or sort types

21,873

Solution 1

As your filter options are totally different entities, you should simply remove all pins on your map and then loop the appropriate array with new filtered datas for adding new pins.

Solution 2

Use [MKMapView removeAnnotations:] and [MKMapView addAnnotation:] to change the pins that are on the map.

Solution 3

  1. remove all Annotations using [MKMapView removeAnnotations:] 2. recreate the annotation array based on the new sorting 3. add the new annotation to the map
Share:
21,873
Apple_iOS0304
Author by

Apple_iOS0304

Updated on January 07, 2020

Comments

  • Apple_iOS0304
    Apple_iOS0304 over 4 years

    I have an application where the map view has several pins and annotations. These pins should refresh or reload based on the various sort options I have on my view. e.g. The pins represent various buildings, and the filter options are like, Library, Museum, Movie Theater, All Attractions, etc.

    I have tried using

    [MapView reloadInputViews];
    

    based on the filtered array after choosing an option. But it simply does not work for me. Any ideas how this would be implemented? Thanks in advance!

  • Hashim MH
    Hashim MH over 11 years
    1. remove all Annotations using [MKMapView removeAnnotations:] 2. recreate the annotation array based on the new sorting 3. add the new annotation to the map
  • Apple_iOS0304
    Apple_iOS0304 over 11 years
    Thanks for the answer.. I was thinking of something similar, but was curious if there is another way to refresh the maps completely. Thanks Mate!
  • Chad Parker
    Chad Parker over 3 years
    Make sure to call these on the main thread.