3
我有一個分組引腳,我想放大。當然,我知道這個針的座標,並且它的觀點是正確的。我只是想將地圖縮放到正確的區域,以便羣集完全展開顯示所有引腳(加上一點填充)。這樣做的好方法是什麼?將MKMapView縮放到MKAnnotationView的框架
旁註:
在我的設置集羣針會自動擴展到各個引腳,當變焦水平的提高,所以我好那裏。我需要知道的是如何根據羣集引腳的框架和座標將MapView設置爲新的區域。
我有一個分組引腳,我想放大。當然,我知道這個針的座標,並且它的觀點是正確的。我只是想將地圖縮放到正確的區域,以便羣集完全展開顯示所有引腳(加上一點填充)。這樣做的好方法是什麼?將MKMapView縮放到MKAnnotationView的框架
旁註:
在我的設置集羣針會自動擴展到各個引腳,當變焦水平的提高,所以我好那裏。我需要知道的是如何根據羣集引腳的框架和座標將MapView設置爲新的區域。
開始通過去除組銷
[mapView removeAnnotation:groupAnnotation];
然後在集羣中添加銷
[mapView addAnnotations:clusterAnnotations];
然後確定區域放大到
CLLocationDegrees minLat = 90;
CLLocationDegrees maxLat = -90;
CLLocationDegress minLong = 180;
CLLocationDegrees maxLong = -180
[clusterAnnotations enumerateUsingBlock:^(id<MKAnnotation> annotation, NSUInteger idx, BOOL *stop) {
CLLocationCoordinate2D coordinate = annotation.coordinate;
minLat = MIN(minLat, coordinate.latitude);
maxLat = MAX(maxLat, coordinate.latitude);
minLong = MIN(minLong, coordinate.longitude);
maxLong = MAX(maxLong, coordinate.longitude);
}
CLLocationCoordinate2D center = CLLocationCoordinate2DMake((minLat + maxLat)/2.f, (minLong + maxLong)/2.f);
MKCoordinateSpan span = MKCoordinateSpanMake((maxLat - minLat)*1.25, (maxLong - minLong)*1.25); //1.25 is for padding
MKCoordinateRegion region = MKCoordinateRegionMake(center, span);
[mapView setRegion:[mapView regionThatFits:region] animated:YES];