0
상황 : MapKit을 사용하여지도에 여러 위치를 표시하고 있습니다. 맵의 모든 점을 창에 맞게 허용하는 범위를 계산하는 코드가 있습니다. 방금 최근에 가장 가까운 위치의 콜 아웃 버블 (적절한 용어?)이 표시되도록 코드를 추가했습니다. 불행히도 설명 선 거품은 창의 경계에 맞지 않습니다. 이상적인 점은 모든 주석과 가장 가까운 위치의 콜 아웃 버블에 맞게 줌을 조정하고 싶습니다. 이 작업을 수행하는 방법에 대한 제안 사항은 무엇입니까? 내 줌 방법은 다음과 같습니다.iOS에서 주석 설명 선의 위치를 얻으려는 경우
-(void)zoomToFitMapAnnotations:(MKMapView*)mv
{
if([mv.annotations count] == 0)
return;
CLLocationCoordinate2D topLeftCoord;
topLeftCoord.latitude = -90;
topLeftCoord.longitude = 180;
CLLocationCoordinate2D bottomRightCoord;
bottomRightCoord.latitude = 90;
bottomRightCoord.longitude = -180;
for(WaybackAnnotation *annotation in [mv annotations])
{
if ([annotation isKindOfClass:[WaybackAnnotation class]])
{
topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude);
topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);
bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);
}
}
MKCoordinateRegion region;
region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5;
region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5;
region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1; // Add a little extra space on the sides
region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1; // Add a little extra space on the sides
region = [mv regionThatFits:region];
[mv setRegion:region animated:YES];
}
미리 감사드립니다. James