如何将图像旋转到特定位置。该应用程序获取用户位置,它应显示目标方向,如指南针,但只有它不显示北方显示固定位置(纬度,长)。这是我尝试的代码,但它没有运行,我不知道为什么。长控制台只能这样:
Latitude: 45.812682 Longitude: 15.989521 Distance: 950.569458
此日志是上述代码(viewdidload)的一部分
#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);
}