0

私はそれにMKMapView多くを持っMKAnnotationsています。ボタンをクリックすると、別の注釈のセットが追加されます。

ボタンをクリックすると、注釈の配列が表示されます。注釈の配列をに追加しMkmapviewます。

マップビューを、ズームアウトまたはズームインせずに新しい注釈が追加される領域に移動したいと思います。

解決策を手伝ってください。

4

2 に答える 2

0

注釈の配列の座標の1つに中心を設定すると、目的に役立つと思います

[_mapView setCenterCoordinate:annotationCoOrd zoomLevel:_zoomLvl animated:YES];

ここで、annotationCoOrd は配列内の座標の 1 つで、_zoomLvl は現在のズーム レベルです。

ここにコードを投稿すると、より役に立ちます。

ズームレベル

- (double)getZoomLevel{
MKCoordinateRegion reg=self.region; // the current visible region
MKCoordinateSpan span=reg.span; // the deltas
CLLocationCoordinate2D centerCoordinate=reg.center; // the center in degrees
// Get the left and right most lonitudes
CLLocationDegrees leftLongitude=(centerCoordinate.longitude-(span.longitudeDelta/2));
CLLocationDegrees rightLongitude=(centerCoordinate.longitude+(span.longitudeDelta/2));
CGSize mapSizeInPixels = self.bounds.size; // the size of the display window

// Get the left and right side of the screen in fully zoomed-in pixels
double leftPixel=[self longitudeToPixelSpaceX:leftLongitude]; 
double rightPixel=[self longitudeToPixelSpaceX:rightLongitude];
// The span of the screen width in fully zoomed-in pixels
double pixelDelta=abs(rightPixel-leftPixel);

// The ratio of the pixels to what we're actually showing
double zoomScale= mapSizeInPixels.width /pixelDelta;
// Inverse exponent
double zoomExponent=log2(zoomScale);
// Adjust our scale
double zoomLevel=zoomExponent+20; 
return zoomLevel;

}

- (double)longitudeToPixelSpaceX:(double)longitude
{
return round(MERCATOR_OFFSET + MERCATOR_RADIUS * longitude * M_PI / 180.0);
}

- (double)latitudeToPixelSpaceY:(double)latitude
{
return round(MERCATOR_OFFSET - MERCATOR_RADIUS * logf((1 + sinf(latitude * M_PI / 180.0)) / (1 - sinf(latitude * M_PI / 180.0))) / 2.0);
}

マップのズーム レベルを取得するには、上記のコードを MKMapView 実装に追加します (MKMapview 実装をオーバーライドします)。

于 2013-02-21T06:41:27.037 に答える
0

ズームなしで移動するにはベロメソッドを使用します

  [mapview setCenterCoordinate:cordinate animated:YES];
于 2013-02-21T06:52:49.203 に答える