我有一组注释。我正在计算每个注释与用户位置之间的距离。我想知道的是,我怎样才能找到这些距离中最近的 3 个注释?
这是我计算从用户位置到注释的距离的方法。
CLLocation *userLocation = self.mapView.userLocation.location;
for (Annotation *obj in annotations) {
CLLocation *loc = [[CLLocation alloc] initWithLatitude:obj.coordinate.latitude longitude:obj.coordinate.longitude];
// CLLocation *userLocation = [[CLLocation alloc] initWithLatitude:self.mapView.userLocation.coordinate.latitude longitude:self.mapView.userLocation.coordinate.longitude];
CLLocationDistance dist = [loc distanceFromLocation:userLocation];
int distance = dist;
NSLog(@"Distance from Annotations - %i", distance);
}