I have MKMapView (obviously) that shows the location of the housing around the user.
I have a Radius tool which, when made a choice, annotations should add / remove based on the distance around the user.
I have the addition / removal of a fine, but for some reason, the annotations will not appear until I zoom in or out.
This is a method that adds / removes annotations based on distance. I tried two different variations of the method.
Adds new annotations to the array, then adds to the map [mapView addAnnotations:NSArray].
Add annotations when they find them using [mapView addAnnotation:MKMapAnnotation];
1.
- (void)updateBasedDistance:(NSNumber *)distance {
float hudIncrement = ( 1.0f / [[[[self appDelegate] rssParser]rssItems] count]);
[self._mapView removeAnnotations:self._mapView.annotations];
NSMutableArray *tempAnnotations;
for (int i = 0; i < [annotations count]; i++) {
CLLocation *tempLoc = [[CLLocation alloc] initWithLatitude:[[annotations objectAtIndex:i] coordinate].latitude longitude:[[annotations objectAtIndex:i] coordinate].longitude];
CLLocationDistance miles = [self._mapView.userLocation.location distanceFromLocation:tempLoc] * 0.000621371192;
if (miles <= [distance floatValue]){
if (tempAnnotations == nil)
tempAnnotations = [[NSMutableArray alloc] init];
[tempAnnotations addObject:[annotations objectAtIndex:i]];
}
tempLoc = nil;
HUD.progress += hudIncrement;
}
if (tempAnnotations != nil)
[self._mapView addAnnotations:tempAnnotations];
}
2.
- (void)updateBasedDistance:(NSNumber *)distance {
float hudIncrement = ( 1.0f / [[[[self appDelegate] rssParser]rssItems] count]);
[self._mapView removeAnnotations:self._mapView.annotations];
for (int i = 0; i < [annotations count]; i++) {
CLLocation *tempLoc = [[CLLocation alloc] initWithLatitude:[[annotations objectAtIndex:i] coordinate].latitude longitude:[[annotations objectAtIndex:i] coordinate].longitude];
CLLocationDistance miles = [self._mapView.userLocation.location distanceFromLocation:tempLoc] * 0.000621371192;
if (miles <= [distance floatValue])
[self._mapView addAnnotation:[annotations objectAtIndex:i]];
tempLoc = nil;
HUD.progress += hudIncrement;
}
}
I also tried at the end of the method described above:
[self._mapView setNeedsDisplay]
[self._mapView setNeedsLayout]
Also, to force update (somewhere this might work):
self._mapView.showsUserLocation = NO;
self._mapView.showsUserLocation = YES;
, , , .