views:

112

answers:

0

Hi all,

I want to stop my app from loading more annotations after they are all added ( they are added by the user one by one), as the app otherwise crashes. How would you do that? the following code is what i think is important

   (void) loadAndSortPOIs {
[poiArray release];
nextPoiIndex = 0;
NSString *poiPath = [[NSBundle mainBundle] pathForResource:@"pois"
                                                    ofType:@"plist"];
poiArray = [[NSMutableArray alloc] initWithContentsOfFile:poiPath];
CLLocation *homeLocation = [[CLLocation alloc] 
                            initWithLatitude:homeCoordinate.latitude
                            longitude:homeCoordinate.longitude];
for (int i = 0; i < [poiArray count]; i++) {
    NSDictionary *dict = (NSDictionary*) [poiArray objectAtIndex: i];
    CLLocationDegrees storeLatitude = [[dict objectForKey:@"workingCoordinate.latitude"] doubleValue];
    CLLocationDegrees storeLongitude = [[dict objectForKey:@"workingCoordinate.longitude"] doubleValue];
    CLLocation *storeLocation = [[CLLocation alloc]
                                 initWithLatitude:storeLatitude
                                 longitude:storeLongitude];
    CLLocationDistance distanceFromHome = [storeLocation getDistanceFrom: homeLocation];

    NSMutableDictionary *mutableDict = [[NSMutableDictionary alloc]
                                        initWithDictionary:dict];
    [mutableDict setValue:[NSNumber numberWithDouble:distanceFromHome]
                   forKey:@"distanceFromHome"];
    [poiArray replaceObjectAtIndex:i withObject:mutableDict];
    [mutableDict release];
}
[homeLocation release];
// now sort by distanceFromHome

NSArray *sortDescriptors = [NSArray arrayWithObject:
                            [[NSSortDescriptor alloc] initWithKey: @"distanceFromHome"
                                                        ascending: YES]];
[poiArray sortUsingDescriptors:sortDescriptors];

NSLog (@"poiArray: %@", poiArray);

}

Thank you for your help.

Best regards,