1

オーバーレイ ビューの下にある地図の注釈をズームする必要があります。

このメソッドを使用して、2 つの注釈にズームします。

次の理由により、オーバーレイ ビューの下に 2 つの注釈を合わせる方法が見つからないようです。

  • マップの edgePadding を設定すると、下部のピンが非表示になります
  • 地図の中心を設定すると、下部のピンが非表示になります
  • latitudeDelta を設定するとうまくいくと思いますが、ピンが水平に平行である場合は必要ありません + さまざまなケースで面倒になります。

それで、私が見逃したかもしれないこの問題に対するエレガントな解決策があるかどうか疑問に思っていますか?

問題

このオーバーレイは、注釈の吹き出しも非表示にします。最初の問題の解決策があれば、これを修正できると思います。

4

2 に答える 2

3

おそらく、このコードを試して、アノテーションに完全に適合するようにする必要があります。

- (void)zoomMapViewToFitAnnotations:(MKMapView *)mapView animated:(BOOL)animated
{ 
    NSArray *annotations = mapView.annotations;
    int count = [mapView.annotations count];
    if ( count == 0) { return; } //return if no annotations

    //convert NSArray of id <MKAnnotation> into an MKCoordinateRegion that can be used to set the map size
    //can't use NSArray with MKMapPoint because MKMapPoint is not an id
    MKMapPoint points[count]; //C array of MKMapPoint struct
    for( int i=0; i<count; i++ ) //load points C array by converting coordinates to points
    {
        CLLocationCoordinate2D coordinate = [(id <MKAnnotation>)[annotations objectAtIndex:i] coordinate];
        points[i] = MKMapPointForCoordinate(coordinate);
    }
    //create MKMapRect from array of MKMapPoint
    MKMapRect mapRect = [[MKPolygon polygonWithPoints:points count:count] boundingMapRect];
    //convert MKCoordinateRegion from MKMapRect
    MKCoordinateRegion region = MKCoordinateRegionForMapRect(mapRect);

    //add padding so pins aren't scrunched on the edges
    region.span.latitudeDelta  *= ANNOTATION_REGION_PAD_FACTOR;
    region.span.longitudeDelta *= ANNOTATION_REGION_PAD_FACTOR;
    //but padding can't be bigger than the world
    if( region.span.latitudeDelta > MAX_DEGREES_ARC ) { region.span.latitudeDelta  = MAX_DEGREES_ARC; }
    if( region.span.longitudeDelta > MAX_DEGREES_ARC ){ region.span.longitudeDelta = MAX_DEGREES_ARC; }

    //and don't zoom in stupid-close on small samples
    if( region.span.latitudeDelta  < MINIMUM_ZOOM_ARC ) { region.span.latitudeDelta  = MINIMUM_ZOOM_ARC; }
    if( region.span.longitudeDelta < MINIMUM_ZOOM_ARC ) { region.span.longitudeDelta = MINIMUM_ZOOM_ARC; }
    //and if there is a sample of 1 we want the max zoom-in instead of max zoom-out
    if( count == 1 )
    { 
        region.span.latitudeDelta = MINIMUM_ZOOM_ARC;
        region.span.longitudeDelta = MINIMUM_ZOOM_ARC;
    }
    [mapView setRegion:region animated:animated];
}

したがって、パディング、最大度アーク、最小ズームアークを定義する必要があります。例の場合 このようにする必要があります:

#define MINIMUM_ZOOM_ARC 0.05 //approximately 1 miles (1 degree of arc ~= 69 miles)
#define ANNOTATION_REGION_PAD_FACTOR 1.25
#define MAX_DEGREES_ARC 360

うまくいけば、あなたはそれを好きになるでしょう、乾杯

于 2012-12-20T17:18:33.787 に答える
0

オーバーレイにタッチポイントが必要な場合は、オーバーレイのuserintercationを無効に設定します。

ズームレベルを設定するために、ポイントをプロットした後にいくつかの調整を行いました。lat longの平均を計算してから、オーバーレイのサイズに応じてlatlongを調整できます。これが私がしたことです:

            float latAvg,longAvg;


            latAvg = (location1.latitude + location.latitude)/2;
            longAvg = (location1.longitude + location.longitude)/2;
            MKCoordinateSpan span;// = MKCoordinateSpanMake(0.006, 0.006);

            span.latitudeDelta = fabs(location1.latitude - location.latitude);
            span.longitudeDelta = fabs(location1.longitude - location.longitude);


//Then adjust the lat longs delta according to your need.

            span.latitudeDelta = span.latitudeDelta + 0.0010;
            span.longitudeDelta = span.longitudeDelta + 0.0010;

            CLLocationCoordinate2D locationLatlng;
            locationLatlng.latitude = latAvg;
            locationLatlng.longitude = longAvg;

            MKCoordinateRegion viewRegion = MKCoordinateRegionMake(locationLatlng, span);


            [map setRegion:viewRegion animated:YES];

            [map regionThatFits:viewRegion];
于 2012-12-20T13:41:39.653 に答える