【发布时间】:2011-03-07 22:43:32
【问题描述】:
我正在使用 MKMapKit 来获取 100 公里半径内的最近位置。但是我想知道如何对数组进行排序,以便在数组顶部给我最近的五个注释。
我当前的代码是:
CLLocation *currentlocation = [[CLLocation alloc] initWithLatitude:annotation.coordinate.latitude longitude:annotation.coordinate.longitude];
annotation.distanceToTarget = [currentlocation distanceFromLocation:usrlocation];
annotation.title = [dict objectForKey:@"name"];
annotation.subtitle = [NSString stringWithFormat:@"%@, %@, %@",[dict objectForKey:@"street"],[dict objectForKey:@"county"], [dict objectForKey:@"postcode"]];
annotation.subtitle = [annotation.subtitle stringByReplacingOccurrencesOfString:@", ," withString:@""];
if (annotation.distanceToTarget/1000 < 168) {
abc++;
NSLog(@"Distances Lower Than 168: %i", abc);
[storesLessThan100KAway addObject:annotation];
NSLog(@"Stores Count: %i", [storesLessThan100KAway count]);
}
for (int i = 0; i <= 5; i++) {
//NSLog(@"Stores Count For Loop: %i", [storesLessThan100KAway count]);
if ([storesLessThan100KAway count] > 5) {
[mapView addAnnotation:[storesLessThan100KAway objectAtIndex:i]];
}
}
【问题讨论】:
标签: iphone objective-c xcode ios4 sorting