Ios 将图像箭头旋转到特定位置

Ios 将图像箭头旋转到特定位置,ios,objective-c,xcode,Ios,Objective C,Xcode,如何将图像旋转到特定位置。该应用程序获取用户位置,并应显示目的地方向,类似于指南针,但它不显示北,而是显示固定位置LAT,long。这是我尝试过的代码,但它没有运行,我不知道为什么。长控制台仅能解决以下问题: 此日志是上述codeviewdidload的一部分 #define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI)) double degrees = 0; - (void)viewDidLo

如何将图像旋转到特定位置。该应用程序获取用户位置,并应显示目的地方向,类似于指南针,但它不显示北,而是显示固定位置LAT,long。这是我尝试过的代码,但它没有运行,我不知道为什么。长控制台仅能解决以下问题:

此日志是上述codeviewdidload的一部分

    #define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI))
    double degrees = 0;
         - (void)viewDidLoad {
                [super viewDidLoad];
                // Do any additional setup after loading the view, typically from a nib.
                // Check for GPS errors
                CLLocationManager *locationManager;

                // Get user location
                locationManager = [[CLLocationManager alloc] init];
                locationManager.delegate = self;
                locationManager.distanceFilter = kCLDistanceFilterNone;
                locationManager.desiredAccuracy = kCLLocationAccuracyBest;
                [locationManager startUpdatingLocation];
                [locationManager startUpdatingHeading];
        }
                #define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI))
                #define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
                -(void) calculateUserAngle:(CLLocationCoordinate2D)current {
                    double x = 0, y = 0 , deg = 0,delLon = 0;


                    float finish_latitude = 45.81;
                    float finish_longitude = 15.90;

                    float fixLon = finish_longitude;
                    float fixLat = finish_latitude;


                    delLon = fixLon - current.longitude;
                    y = sin(delLon) * cos(fixLat);
                    x = cos(current.latitude) * sin(fixLat) - sin(current.latitude) * cos(fixLat) * cos(delLon);
                    deg = RADIANS_TO_DEGREES(atan2(y, x));

                    if(deg<0){
                        deg = -deg;
                    } else {
                        deg = 360 - deg;
                    }
                    degrees = deg; 
NSLog(@"degrees: %f",degrees);

                }

                -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

                    CLLocationCoordinate2D here = newLocation.coordinate;
                    [self calculateUserAngle:here];
                }

                - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
                {
                    direction.transform = CGAffineTransformMakeRotation((degrees-newHeading.trueHeading) * M_PI / 180);
 NSLog(@"Rotation: %f",(degrees-newHeading.trueHeading) * M_PI / 180);
                }

你的学位声明在哪里?对不起,忘了键入它
    #define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI))
    double degrees = 0;
         - (void)viewDidLoad {
                [super viewDidLoad];
                // Do any additional setup after loading the view, typically from a nib.
                // Check for GPS errors
                CLLocationManager *locationManager;

                // Get user location
                locationManager = [[CLLocationManager alloc] init];
                locationManager.delegate = self;
                locationManager.distanceFilter = kCLDistanceFilterNone;
                locationManager.desiredAccuracy = kCLLocationAccuracyBest;
                [locationManager startUpdatingLocation];
                [locationManager startUpdatingHeading];
        }
                #define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI))
                #define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
                -(void) calculateUserAngle:(CLLocationCoordinate2D)current {
                    double x = 0, y = 0 , deg = 0,delLon = 0;


                    float finish_latitude = 45.81;
                    float finish_longitude = 15.90;

                    float fixLon = finish_longitude;
                    float fixLat = finish_latitude;


                    delLon = fixLon - current.longitude;
                    y = sin(delLon) * cos(fixLat);
                    x = cos(current.latitude) * sin(fixLat) - sin(current.latitude) * cos(fixLat) * cos(delLon);
                    deg = RADIANS_TO_DEGREES(atan2(y, x));

                    if(deg<0){
                        deg = -deg;
                    } else {
                        deg = 360 - deg;
                    }
                    degrees = deg; 
NSLog(@"degrees: %f",degrees);

                }

                -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

                    CLLocationCoordinate2D here = newLocation.coordinate;
                    [self calculateUserAngle:here];
                }

                - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
                {
                    direction.transform = CGAffineTransformMakeRotation((degrees-newHeading.trueHeading) * M_PI / 180);
 NSLog(@"Rotation: %f",(degrees-newHeading.trueHeading) * M_PI / 180);
                }