【发布时间】:2011-03-18 03:12:10
【问题描述】:
我正在使用指南针航向来旋转 MKMapView。旋转有点生涩,所以我试图像 iphone 上的谷歌地图一样过滤它(或似乎做了一些诡计)。
我正在尝试使用移动平均公式过滤来自 iphone 指南针的读数,但它在 359 和 0 之间的交叉处失败,因为它开始从 35x 向后平均到 0,并导致地图在接近时向后旋转从西往北。
任何想法最好的方法是过滤此数据,使其从 359 回到零并保持滚动平均值。
代码在这里:
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
static float xd=0;
static float k = 0.22;
// Moving average formula
xd = k * xd + (1.0 - k) * newHeading.magneticHeading;
NSLog(@"%0.2f : %0.2f", newHeading.magneticHeading, xd);
[map setTransform:CGAffineTransformMakeRotation((-1 * xd * M_PI) /180)];}
感谢您的帮助
【问题讨论】:
-
查看最近关于平均角度的问题:stackoverflow.com/q/5343629/5987
标签: iphone filter mkmapview compass-geolocation moving-average