• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

objective-c - 如何在不影响 MKMapView 性能的情况下放置 MKAnnotation

[复制链接]
菜鸟教程小白 发表于 2022-12-12 16:39:54 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我的 map 上有 2800 多个位置。 但是当我把它们放在 map 上时, map 是卡住的。我只能等到所有注释数据都可用。

    - (void)mapViewMKMapView *)mapView regionDidChangeAnimatedBOOL)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 *)mapViewMKMapView *)mapView viewForAnnotationid <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;

}



Best Answer-推荐答案


有了这么多注释,我会将它们聚集在一起,以便在放大时获得更多细节。我用这种方式在 map 上放了几千 block ,效果很好。如果你搜索它,有很多关于 map 针聚类的信息。

这里有一个 commercial option例如(没有连接,没有使用过),但是如果你环顾四周,你会看到很多关于如何自己实现它的信息。

关于objective-c - 如何在不影响 MKMapView 性能的情况下放置 MKAnnotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6570729/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap