I use the following for a loop to manage / find the five closest annotations for a user's location, and then set them as mapView annotations.
for (int i = 0; i <= 5; i++) {
if ([storesLessThan100KAway count] > 5) {
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"distanceToTarget" ascending:YES];
NSArray *newArray = [storesLessThan100KAway sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]];
[mapView addAnnotation:[newArray objectAtIndex:i]];
if ([[mapView annotations] count] > 4) {
[descriptor release];
[dict release];
[currentlocation release];
[usrlocation release];
[annotation release];
[paul drain];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
return;
}
}
However, annotations added to the map will not be displayed until the map is enlarged or moved. Anyway, could I stop this?
source
share