私はそれにMKMapView
多くを持っMKAnnotations
ています。ボタンをクリックすると、別の注釈のセットが追加されます。
ボタンをクリックすると、注釈の配列が表示されます。注釈の配列をに追加しMkmapview
ます。
マップビューを、ズームアウトまたはズームインせずに新しい注釈が追加される領域に移動したいと思います。
解決策を手伝ってください。
私はそれにMKMapView
多くを持っMKAnnotations
ています。ボタンをクリックすると、別の注釈のセットが追加されます。
ボタンをクリックすると、注釈の配列が表示されます。注釈の配列をに追加しMkmapview
ます。
マップビューを、ズームアウトまたはズームインせずに新しい注釈が追加される領域に移動したいと思います。
解決策を手伝ってください。
注釈の配列の座標の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 実装をオーバーライドします)。
ズームなしで移動するにはベロメソッドを使用します
[mapview setCenterCoordinate:cordinate animated:YES];