0

我需要在地图上放置热点。所有这些都用CoreData保存(大约25000)。所以我需要25000个注释。我还为 HotSpot Entity 实现了 MKAnnotation 协议。

针对这种情况选择的解决方案是多线程。但是在地图上出现大头针后,其中一些没有数据(数据)。

这是在数组中填充数据的代码

- (void)addAnnotationsForCurrentLocation {
    NSInteger hotSpotsCount = [HotSpot MR_countOfEntities];
    self.testSpotsArray = [[NSMutableArray alloc] initWithCapacity:hotSpotsCount];
    NSInteger lastThread;
    NSInteger threads = 5;
    //calculate how much spots will be in the 
    NSInteger spotsInThread = hotSpotsCount/threads;
    //calclulate how mush threads will be in one spot
    lastThread = hotSpotsCount - spotsInThread*(threads-1);
    dispatch_queue_t firstThreadQueue = dispatch_queue_create("com.thecloud.firstThreadQueue", DISPATCH_QUEUE_CONCURRENT);
    dispatch_queue_t secondThreadQueue = dispatch_queue_create("com.thecloud.secondThreadQueue", DISPATCH_QUEUE_CONCURRENT);
    dispatch_queue_t thirdThreadQueue = dispatch_queue_create("com.thecloud.thirdThreadQueue", DISPATCH_QUEUE_CONCURRENT);
    dispatch_queue_t forthThreadQueue = dispatch_queue_create("com.thecloud.forthThreadQueue", DISPATCH_QUEUE_CONCURRENT);
    dispatch_queue_t fifthThreadQueue = dispatch_queue_create("com.thecloud.fifthThreadQueue", DISPATCH_QUEUE_CONCURRENT);

    dispatch_group_t fillArrayGroup = dispatch_group_create();
    NSLock *arrayLock = [[NSLock alloc] init];

    dispatch_group_async(fillArrayGroup, firstThreadQueue, ^{
        [self fetchWithOffest:0 andLimit:spotsInThread andLock:arrayLock];
        DDLogInfo(@"com.thecloud.firstThreadQueue and self.testSpotsArray objects - %i", [self.testSpotsArray count]);
    });

    //Other Queue

    dispatch_group_notify(fillArrayGroup, dispatch_get_main_queue(), ^{
        [self.treeController setAnnotations:self.testSpotsArray];
    });

    dispatch_release(fillArrayGroup);
}
- (void)fetchWithOffest:(NSInteger)offset andLimit:(NSInteger)limit andLock:(NSLock *)arrayLock {
    NSFetchRequest *request = [HotSpot MR_requestAll];
    [request setFetchOffset:offset];
    [request setFetchLimit:limit];
    [request setReturnsObjectsAsFaults:NO];
    NSArray *array = [HotSpot MR_executeFetchRequest:request];
    for (int i=0; i < [array count]; i++) {
        HotSpot *spot = (HotSpot *)[array objectAtIndex:i];
        [spot convertLogitudeAndLattitudeToLocationCoordinate];
        [arrayLock lock];
        [self.testSpotsArray addObject:spot];
        [arrayLock unlock];
    }
}

在此之后,当我点击某些引脚时,不会出现带有描述的弹出窗口。任何解决方案都可以在注释数组中的每个对象中包含完整数据?

UPD

问题解决了。我确实改变了我的实体模型。现在当我将实体添加到注释数组而不是

-(NSString *)title {
    return self.title;
}

-(NSString *)subtitle {
    return self.spotToAddress.addressLine1;
}

-(CLLocationCoordinate2D) coordinate {
    return CLLocationCoordinate2DMake([self.latitude doubleValue], [self.longitude doubleValue]);
}

我使用直接分配

- (void)prepareAnnotation {
    _title = self.name;
    _subtitle = self.spotToAddress.addressLine1;
    _coordinate = CLLocationCoordinate2DMake([self.latitude doubleValue], [self.longitude doubleValue]);
}
4

1 回答 1

0

问题解决了。我确实改变了我的实体模型。现在当我将实体添加到注释数组而不是

-(NSString *)title {
    return self.title;
}

-(NSString *)subtitle {
    return self.spotToAddress.addressLine1;
}

-(CLLocationCoordinate2D) coordinate {
    return CLLocationCoordinate2DMake([self.latitude doubleValue], [self.longitude doubleValue]);
}

我使用直接分配

- (void)prepareAnnotation {
    _title = self.name;
    _subtitle = self.spotToAddress.addressLine1;
    _coordinate = CLLocationCoordinate2DMake([self.latitude doubleValue], [self.longitude doubleValue]);
}
于 2013-07-30T15:08:42.133 回答