2010-02-28 65 views
1

我想根據用戶的當前路線在我的應用中旋轉地圖視圖。 (我不喜歡使用內置的compasse,因爲只有3GS使用它,並且受到來自其他機器,即您自己的汽車的太多幹擾)。僅旋轉MapView的內容

CGAffineTransformMakeRotation方法將旋轉整個地圖視圖,因此Google Logo不會再位於屏幕的右下角。所有的註釋視圖也會旋轉,看起來很奇怪。

是否有人知道如何旋轉MkMapView的內容(街道drwaings)?

感謝

回答

2

這裏是我如何旋轉的MapView(見Rotate MapView using Compass orientation):

[self.mapView setTransform:CGAffineTransformMakeRotation(-1 * currentHeading.magneticHeading * 3.14159/180)]; 

然後保持的註解視圖的方向與設備的頂部:

for (MKAnnotation *annotation in self.mapView.annotations) { 
    MKAnnotationView *annotationView = [self.mapView viewForAnnotation:annotation]; 
    [annotationView setTransform:CGAffineTransformMakeRotation(currentHeading.magneticHeading * 3.14159/180)]; 
} 

如果你希望annotationViews的旋轉點被稱爲底部中心,我相信你會設置每個視圖的anchorPoint如下:

annotationView.layer.anchorPoint = CGPointMake(0.5, 1.0); 

我仍然有,當我做到這一點,但(可能是相同的問題計算器的問題:改變-MY-calayers-anchorpoint-移動-中,視圖)的annotationView位置改變的一些問題。

+1

我正在做一個類似的事情根據CoreLocation retireived旋轉一個MapView。我在github的MIT下發布了它(還包括像BarButtonItem那樣更有用的東西,其行爲與內置的Google Maps App類似) - https://github.com/myell0w/MTLocation – myell0w 2011-03-06 13:59:29

+0

我該如何聲明currentHeading? ? – 2011-05-29 11:46:49

+0

嘗試在didUpdateHeading內部使用newHeading變量:(CLHeading *)newHeading handler – fyasar 2011-06-07 08:26:04