0

状況は次のとおりです。MapKitを使用して、地図上にいくつかの場所を表示しています。マップ上のすべてのポイントがウィンドウに収まるようにする境界を計算するコードがあります。最近、最も近い場所のコールアウトバブル(適切な用語?)を表示できるようにするコードを追加しました。残念ながら、コールアウトバブルはウィンドウの境界に収まりません。理想的には、ズームを調整して、すべての注釈と最も近い場所のコールアウトバブルに合うようにします。これを行う方法について何か提案はありますか?これが私のズーム方法です:

-(void)zoomToFitMapAnnotations:(MKMapView*)mv
{   
    if([mv.annotations count] == 0)
            return;

    CLLocationCoordinate2D topLeftCoord;
    topLeftCoord.latitude = -90;
    topLeftCoord.longitude = 180;

    CLLocationCoordinate2D bottomRightCoord;
    bottomRightCoord.latitude = 90;
    bottomRightCoord.longitude = -180;

    for(WaybackAnnotation *annotation in [mv annotations])
    {
        if ([annotation isKindOfClass:[WaybackAnnotation class]])
        {
            topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude);
            topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);

            bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
            bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);
        }
    }

    MKCoordinateRegion region;
    region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5;
    region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5;
    region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1; // Add a little extra space on the sides
    region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1; // Add a little extra space on the sides

    region = [mv regionThatFits:region];
    [mv setRegion:region animated:YES];
}

前もって感謝します!ジェームズ

4

1 に答える 1

3

バブルは常にピンの上に表示されるため、上部に追加のパディングが必要です。あなたはスクリーンピクセルでパディングの高さを知っています。MKMapViews変換方法(およびフレンド)を使用-convertRect:toRegionFromView:して、これらを地理座標に変換します。

于 2011-03-09T11:13:38.437 に答える