2010-02-28 68 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