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];