2013-02-21 59 views

回答

0

我想設置中心註釋的數組中的座標之一將成爲你的目的

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

其中,annotationCoOrd是你的數組中的座標之一, _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實現)。

與放大招
+0

我怎麼能得到的MKMapView當前縮放級別? – 2013-02-21 06:55:20

+0

檢查我的答案上的編輯。可能對其他實現有用。但是,Gaurav的代碼行將做到這一點:) – Kamath5687 2013-02-21 07:08:37

+0

@ Kamath5687:[self longitudeToPixelSpaceX:rightLongitude];請您詳細說明函數嗎? – 2013-02-21 07:55:12

0

貝羅使用方法

[mapview setCenterCoordinate:cordinate animated:YES];