I want to zoom my mapview to show atleast one annotation of the nearest annotations, with highest possible zoom, and the user location. I have tried the following:
-(void)zoomToFitNearestAnnotationsAroundUserLocation {
MKMapPoint userLocationPoint = MKMapPointForCoordinate(self.restaurantsMap.userLocation.coordinate);
MKCoordinateRegion region;
if ([self.restaurantsMap.annotations count] > 1) {
for (id<MKAnnotation> annotation in self.restaurantsMap.annotations) {
MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
CLLocationDistance distanceBetweenAnnotationsAndUserLocation = MKMetersBetweenMapPoints(annotationPoint, userLocationPoint);
region = MKCoordinateRegionMakeWithDistance(self.restaurantsMap.userLocation.coordinate, distanceBetweenAnnotationsAndUserLocation, distanceBetweenAnnotationsAndUserLocation);
}
[self.restaurantsMap setRegion:region animated:YES];
}
}
How would I manage to save 2-3 of the nearest distances and make a region based on that info?