我使用以下for循环来管理/找出用户位置的五个最近注释,然后将它们设置为mapView的注释。
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;
}
}
但是,在放大或移动地图之前,不会显示添加到地图中的注释。无论如何我可以阻止这个吗?
答案 0 :(得分:1)
MKMapView是UIView的子类 - 您可以尝试调用[mapView setNeedsDisplay]吗?
如果不起作用:
// Force update of map view.
CLLocationCoordinate2D center = [mapView centerCoordinate];
[mapView setCenterCoordinate:center];
答案 1 :(得分:1)
尝试将这些行放入计时器并在完成添加注释后将其停止
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];