2011-12-29 153 views
2

我用下面的代碼來顯示用戶的位置,從地圖中心:縮放級別限制了我的谷歌地圖iOS應用

... 
// start off by default current position 
AppManager *appManager = [AppManager sharedManager]; 
MKCoordinateRegion newRegion; 
newRegion.center.latitude = [appManager.currentlatitude floatValue]; 
newRegion.center.longitude = [appManager.currentlongitude floatValue]; 
newRegion.span.latitudeDelta = 0.06; 
newRegion.span.longitudeDelta = 0.06; 
[self.mapView setRegion:newRegion animated:YES]; 
[self.view insertSubview:mapView atIndex:0]; 
... 

的事情是,我不管理播放時降低縮放級別不夠用「newRegion.span.latitudeDelta」和「newRegion.span.longitudeDelta」值。當我想要有幾百個時,變焦只顯示一個寬度爲30公里的區域。

對於我所看到的,經度的值爲0.06應該顯示180度(地球的一半)(對於緯度0),那麼對於43的緯度,我認爲我應該看到超過30公里。

有什麼想法?

回答

7

latitudeDeltalongitudeDelta因此0.06的值是以km爲單位的相對小的距離。要顯示「地球的一半」,您必須將longitudeDelta設置爲180.0。

如果你知道的距離(如公里)。要顯示,這將是更容易使用,而不是試圖自己做轉換MKCoordinateRegionMakeWithDistance功能:

CLLocationCoordinate2D newCenter = 
    CLLocationCoordinate2DMake([appManager.currentlatitude floatValue], 
           [appManager.currentlongitude floatValue]); 

MKCoordinateRegion newRegion = 
    MKCoordinateRegionMakeWithDistance(newCenter, 200000, 200000); 

最後兩個參數是latitudinalMeterslongitudinalMeters所以上面的例子將跨度設置爲200公里×200公里。

記住地圖視圖將根據需要根據地圖視圖的比例和可顯示的縮放級別調整區域。

+0

不錯,我只是想知道如何做到這一點。 – markhunte 2011-12-29 15:15:42

+0

@ anna-karenina很棒,正是我需要的。非常感謝。 – Luc 2011-12-30 14:29:18

相關問題