2
私のマップには2800を超える場所があります。 しかし、私はそれらを置いている時マップは凍っています。私は何もすることはできませんが、注釈データがすべて利用可能になるまで待ってください。MKMapViewのパフォーマンスに影響を与えずにMKAnnotationを配置する方法
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
NSAutoreleasePool *pool_mr = [[NSAutoreleasePool alloc] init];
NSLog(@"mapView:regionDidChangeAnimated:");
NSLog(@"latitude: %f, longitude: %f", regionsMapView.centerCoordinate.latitude, regionsMapView.centerCoordinate.longitude);
NSLog(@"latitudeDelta: %f, longitudeDelta: %f", regionsMapView.region.span.latitudeDelta, regionsMapView.region.span.longitudeDelta);
if (regionsMapView.region.span.latitudeDelta < 0.007) {
NSLog(@"SHOW ANNOTATIONS");
NSArray *annotations = [regionsMapView annotations];
AddressAnnotation *annotation = nil;
for (int i=0; i<[annotations count]; i++)
{
NSLog(@"%i", i);
annotation = (AddressAnnotation*)[annotations objectAtIndex:i];
[[regionsMapView viewForAnnotation:annotation] setHidden:NO];
}
}else {
NSLog(@"HIDE ANNOTATIONS");
NSArray *annotations = [regionsMapView annotations];
AddressAnnotation *annotation = nil;
for (int i=0; i<[annotations count]; i++)
{
NSLog(@"%i", i);
annotation = (AddressAnnotation*)[annotations objectAtIndex:i];
[[regionsMapView viewForAnnotation:annotation] setHidden:YES];
}
}
[pool_mr release];
}
そして、もう一つの方法は、以下のようなものです:注釈の数と
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation, AddressAnnotation>) annotation {
//NSAutoreleasePool *pool5 = [[NSAutoreleasePool alloc] init];
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]]){
NSLog(@"MKUserLocation");
return nil;
}
else {
NSLog(@"mapView:viewForAnnotation>>>");
NSLog(@"%@", [annotation markerColor]);
NSLog(@"image: %@", [NSMutableString stringWithFormat:@"MKPinAnnotationView_%@.png",[annotation markerColor]]);
MKPinAnnotationView *annView=[[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:[annotation markerColor]] autorelease];
//annView.pinColor = MKPinAnnotationColorPurple;
UIImage *annotationImage = [[UIImage imageNamed:[NSMutableString stringWithFormat:@"MKPinAnnotationView_%@.png",[annotation markerColor]]] autorelease];
annView.image = annotationImage;
annView.animatesDrop = NO;
annView.canShowCallout = YES;
//annView.draggable = NO;
//annView.highlighted = NO;
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}
//[pool5 release];
NSLog(@"<<<mapView:viewForAnnotation");
return nil;
}