2010-02-11 135 views
4

我在iPhone上實現地圖應用程序。我想讓地圖放大用戶的當前位置。 我想根據精確度縮放(模擬地圖應用程序的工作方式)。MKMapView:如何根據精度設置區域跨度?

進出口實現這種方法:

- (void)locationManager:(CLLocationManager *)manager 
didUpdateToLocation:(CLLocation *)newLocation 
fromLocation:(CLLocation *)oldLocation { 

我所面臨的問題是,CLLocation爲我提供了,這到底意味着米的屬性horizo​​ntalAccuracy和verticalAccuracy,準確性。然而,到中心我用這個地圖:立足horizo​​ntalAccuracy

MKCoordinateRegion region; 
MKCoordinateSpan span; 
region.center = newLocation.coordinate; 
span.latitudeDelta=.005; //THIS IS HARDCODED 
span.longitudeDelta=.005; //THIS IS HARDCODED 
region.span = span; 

[mapView setRegion:region animated:YES]; 

林尋找一種方式來計算latitudeDelta(以度表示)(以米爲單位表示)。

它不需要是一個確切的轉換(我不期待轉換公式,這將需要相當一些計算,包括當前位置),只是一些aprox值。

任何想法?

謝謝。 Gonso

回答

12

無需做計算。只需使用MKCoordinateRegionMakeWithDistance()即可。

+0

應該標記爲正確的答案。 – chakrit 2012-03-12 09:55:31

0

我使用下面的代碼來設置要在MapView中顯示的中心和跨度。它應該工作。

MKCoordinateRegion region = {{0,0},{.5,.5}}; 
region.center.latitude = doubleLattitude; //user defined 
region.center.longitude = doubleLongitude;//user defined 
[mapView setRegion:region animated:YES];