7

ズームインしたいグループ化されたピンがあります。もちろん、私はピンの座標を知っていて、それを正しく見ています。マップを適切な領域にズームして、クラスターが完全に拡張され、すべてのピン(および少しのパディング)が表示されるようにします。これを行うための良い方法は何ですか?

補足:
私のセットアップでは、ズームレベルが上がると、クラスターピンが自動的に個々のピンに拡張されるので、問題ありません。私が知る必要があるのは、クラスターピンのフレームと座標に基づいてMapViewを新しい領域に設定する方法です。

ここに画像の説明を入力してください

4

3 に答える 3

1

グループピンを削除することから始めます

[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];
于 2013-03-16T20:02:54.543 に答える