このアルゴリズムを正しく理解できません。たとえば北を指すのではなく、特定の場所を指すコンパスを作成しようとしています。何かが間違っている。私はこれを理解しようと多くの時間を費やしましたが、私はそれを見つけることができません。何か案は?
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{
double distanceEast = (location.longitude > 0 && otherLocation.longitude < 0) ? 180 - location.longitude + otherLocation.longitude - -180: otherLocation.longitude - location.longitude;
if (distanceEast < 0) {
distanceEast += 360;
}
double distanceWest = (location.longitude < 0 && otherLocation.longitude > 0) ? -180 - location.longitude - 180 - otherLocation.longitude : location.longitude - otherLocation.longitude;
if (distanceWest < 0) {
distanceWest += 360;
}
float latitudinalDifference = (otherLocation.latitude - location.latitude);
float longitudinalDifference = fmin(distanceEast,distanceWest);
float arcTan = atan(longitudinalDifference / latitudinalDifference);
float oldRadian = (-manager.heading.trueHeading *M_PI /180.0f)+arcTan+M_PI;
float newRadian = (-newHeading.trueHeading *M_PI /180.0f)+arcTan+M_PI;
CABasicAnimation *animation;
animation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation.fromValue = [NSNumber numberWithFloat:oldRadian];
animation.toValue = [NSNumber numberWithFloat:newRadian];
animation.duration = 0.5f;
directionsArrow.layer.anchorPoint = CGPointMake(0.5, 0.5);
[directionsArrow.layer addAnimation:animation forKey:@"rotationCompass"];
directionsArrow.transform = CGAffineTransformMakeRotation(newRadian);
}