MapKit와 포함하는 구형을 싶어 이 작업을 수행 MKMapView의 내장 기능 :
showAnnotations(annotations: [MKAnnotation], animated: Bool)
그러나,이 기능은 줌 레벨에 대한 제어를 제공하지 않기 때문에, 나는 아직도 내 자신의 기능을했습니다. 대신 가장 먼 점을 에지로부터 동일한 거리를 갖는 점의 평균을 중심으로
zoomToAnnotations(annotations, zoomLimit) {
// calculate the midpoint as the average latitude and longitude
average_latitude = mean(a.coordinate.latitude for a in annotations)
average_longitude = atan2(mean(sin(a.coordinate.longitude) for a in annotations), mean(cos(a.coordinate.longitude) for a in annotations)) // be careful with degrees and radians in real code
regular_midpoint = coordinate(average_latitude, average_longitude)
// subtract 180 from longitude for the midpoint of the region crossing the meridian
meridian_midpoint = coordinate(average_latitude, average_longitude - 180.0)
if (meridian_midpoint.longitude < -180) {
meridian_midpoint.longitude += 360.0
}
// work out which region will be smaller and center map there
meridian_sum = sum(a.coordinate.distance(meridian_midpoint) for a in annotations)
regular_sum = sum(a.coordinate.distance(regular_midpoint) for a in annotations)
regular_max_distance = max(a.coordinate.distance(regular_midpoint) for a in annotations)
if meridian_sum < regular_sum {
meridian_max_distance = max(a.coordinate.distance(meridian_midpoint) for a in annotations)
centerMapWithRadius(meridian_midpoint, max(zoomLimit, meridian_max_distance))
} else {
regular_max_distance = max(a.coordinate.distance(regular_midpoint) for a in annotations)
centerMapWithRadius(regular_midpoint, max(zoomLimit, regular_max_distance))
}
}
이 방법은 완전하지 않다 : 여기 의사 코드이다.