如何创建一个始终指向该位置的指南针?

时间:2012-08-10 10:29:00

标签: iphone gps xcode4.3

我正在开发一个项目,我需要将指南针指向一个位置。我需要这个指南针总是指向这个位置,即使用户倾斜iphone或移动。我得到了该位置的角度和当前但是我不知道如何实现指向指南针的功能。可以帮助我。

CLLocationDirection direction = newHeading.magneticHeading;
double radians = -direction / 180.0 * M_PI;
//For Rotate Niddle
CGFloat angle = RadiansToDegrees(radians);

double angletothelocation=[self bearingToLocation:destinationLocation];

[self rotateArrowView:arrowView degrees:(angle+radianangle)];

但我的方向错了。任何人都可以建议我这样做吗? 提前谢谢....

1 个答案:

答案 0 :(得分:0)

我们的应用程序正是您想要的这个功能。您的代码略有不同,但我认为您缺少方向修正:

self.arrow.transform = CGAffineTransformMakeRotation(toRadian((headingFloat+angle) + orientationCorrection));

取向校正的地方是:

- (int)fixOrientation {
    switch ([[UIApplication sharedApplication] statusBarOrientation]) {
        case UIInterfaceOrientationPortrait:
            return 0;
        case UIInterfaceOrientationLandscapeLeft:
            return 90;
        case UIInterfaceOrientationLandscapeRight:
            return 270;
        case UIInterfaceOrientationPortraitUpsideDown:
            return 180;
    }
}