3

I am using the following for loop to manage/find out the five nearest annotations to the user location, and then set them as the mapView's annotations.

for (int i = 0; i <= 5; i++) {
            //NSLog(@"Stores Count For Loop: %i", [storesLessThan100KAway count]);
            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 the annotations added to the map will not be shown until the map is zoomed in or moved. Is there anyway that I could stop this?

max_
  • 24,076
  • 39
  • 122
  • 211

2 Answers2

1

Try to put these lines in a Timer and stop it after you finish adding annotations

static float deltaX=.1;
CLLocation *location = [[[CLLocation alloc] initWithLatitude:self.mapView.centerCoordinate.latitude longitude:self.mapView.centerCoordinate.longitude] autorelease];

MKCoordinateRegion region;
region.center = location.coordinate;
MKCoordinateSpan span;

span.latitudeDelta = self.mapView.region.span.latitudeDelta+deltaX;
span.longitudeDelta = self.mapView.region.span.longitudeDelta+deltaX;
deltaX+=.1;
deltaX*=-1;
region.span = span; // Set the region's span to the new span.
[self.mapView setRegion:region animated:0];
mohammad alabid
  • 444
  • 7
  • 21
1

MKMapView is a subclass of UIView -- You could try calling [mapView setNeedsDisplay]?

If that doesn't work:

// Force update of map view.
CLLocationCoordinate2D center = [mapView centerCoordinate];
[mapView setCenterCoordinate:center];
Stephen Poletto
  • 3,645
  • 24
  • 24
  • I actually tried zooming to the user location (for user experience). – max_ Mar 10 '11 at 07:56
  • I am having the exact same problem... how did you end of fixing it? The above answer did not work for me.(see my question here: http://stackoverflow.com/questions/6590958/mapview-have-annotations-appear-one-at-a-time) – Adam Storr Jul 07 '11 at 16:50