0

mkmapview に多くの注釈があります。mkmapview に複数の注釈を表示するには、コードを使用しています

 MKMapRect zoomRect = MKMapRectNull;
 for (id <MKAnnotation> annotation in self.mapView.annotations)
 {
       if([[annotation description]isEqualToString:@"Location"])
      {
            MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
            MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
            if (MKMapRectIsNull(zoomRect)) 
            {
                        zoomRect = pointRect;
            } 
            else 
            {
                        zoomRect = MKMapRectUnion(zoomRect, pointRect);
             }
         }
   }

 MKCoordinateRegion region = MKCoordinateRegionForMapRect(zoomRect);

[self.mapView setRegion:region animated:YES];

注釈がマップ上にプロットされていても、特定の注釈が途切れています。

ここに画像の説明を入力

4

2 に答える 2

0

あなたはこれを試すことができます

- (void)zoomToFitMapAnnotations { 

    if ([mapView.annotations count] == 0) return; 

        int i = 0;
        MKMapPoint points[[mapView.annotations count]];

        //build array of annotation points
        for (id<MKAnnotation> annotation in [mapView annotations])
            points[i++] = MKMapPointForCoordinate(annotation.coordinate);

        MKPolygon *poly = [MKPolygon polygonWithPoints:points count:i];

        [mapView setRegion:MKCoordinateRegionForMapRect([poly boundingMapRect]) animated:YES]; 


}
于 2013-02-19T05:31:46.837 に答える
0

ほとんどではないにしても、多くの場合、計算している四角形は、その場所に表示されている画像ではなく、注釈が指している座標のみを対象としているため、そのような上部にピンがあります。

MKMapView Classを使用して注釈ビューが画面からどれだけ離れているかを確認できる場合がありますが、画面の測定でカバーされるマップの距離を知るには、最初に正しくない四角形にズームする必要があります。

もう 1 つの方法は、マップ ビューのサイズと比較したピンのサイズに基づいて、zoomRect を北方向にわずかに拡大することです。たとえば、(構成された数字を使用して) マップ ビューの高さが 100pt でピンが 10 の場合、zoomRect を 10% 高くする必要があります (上部にピンがあると仮定します。 zoomRect は mapview よりも広いか、10% を追加するだけです。これは、上部に未使用のマップが少しあっても誰も気にしないためです)。

于 2013-02-19T20:03:24.957 に答える