Я использую 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]];
}
}