Objective c 如何在不影响MKMapView性能的情况下放置MKAnnotation
我的地图上有2800多个地点。 但是当我把它们放在地图上时,地图是冻结的。我只能等待所有注释数据可用Objective c 如何在不影响MKMapView性能的情况下放置MKAnnotation,objective-c,ios,xcode,mkmapview,mkannotation,Objective C,Ios,Xcode,Mkmapview,Mkannotation,我的地图上有2800多个地点。 但是当我把它们放在地图上时,地图是冻结的。我只能等待所有注释数据可用 - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{ NSAutoreleasePool *pool_mr = [[NSAutoreleasePool alloc] init]; NSLog(@"mapView:regionDidChangeAnimate
- (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];
}
-(void)地图视图:(MKMapView*)地图视图区域IDChangeAnimated:(BOOL)动画{
NSAutoreleasePool*pool_mr=[[NSAutoreleasePool alloc]init];
NSLog(@“mapView:regionDidChangeAnimated:”);
NSLog(@“纬度:%f,经度:%f”,RegionMapView.centerCoordinate.latitude,RegionMapView.centerCoordinate.longitude);
NSLog(@“latitudeDelta:%f,longitudeDelta:%f”,RegionMapView.region.span.latitudeDelta,RegionMapView.region.span.longitudeDelta);
if(regionsMapView.region.span.latitudeDelta<0.007){
NSLog(“显示注释”);
NSArray*注释=[RegionMapView注释];
AddressAnnotation*annotation=nil;
对于(int i=0;i,有那么多注释,我会对它们进行聚类,以便在放大时获得更多细节。我以这种方式在地图上放置了几千个注释,效果很好。如果搜索,会有很多关于map pin聚类的信息
这里有一个例子(没有连接,没有使用),但是如果你环顾四周,你会看到很多关于如何自己实现它的信息
- (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;
}