Limit Annotation number in Mapkit
Posted
by teddafan
on Stack Overflow
See other posts from Stack Overflow
or by teddafan
Published on 2010-05-31T10:05:50Z
Indexed on
2010/05/31
10:13 UTC
Read the original article
Hit count: 275
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). 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,
© Stack Overflow or respective owner