方位を別のCLLocationに戻すために、CLLocationのカテゴリを作成しようとしています。
私は数式で何か間違ったことをしていると思います(結石は私の強いスーツではありません)。戻されたベアリングは常にオフです。
私はこの質問を見て、正解として受け入れられた変更とそれが参照するWebページを適用しようとしました。
2つのCLLocationCoordinate2D間の方位を計算する
http://www.movable-type.co.uk/scripts/latlong.html
ポインタをありがとう。他の質問からのフィードバックを取り入れようとしましたが、まだ何かが得られていません。
ありがとう
これが私のカテゴリーです-
----- CLLocation + Bearing.h
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@interface CLLocation (Bearing)
-(double) bearingToLocation:(CLLocation *) destinationLocation;
-(NSString *) compassOrdinalToLocation:(CLLocation *) nwEndPoint;
@end
--------- CLLocation + Bearing.m
#import "CLLocation+Bearing.h"
double DegreesToRadians(double degrees) {return degrees * M_PI / 180;};
double RadiansToDegrees(double radians) {return radians * 180/M_PI;};
@implementation CLLocation (Bearing)
-(double) bearingToLocation:(CLLocation *) destinationLocation {
double lat1 = DegreesToRadians(self.coordinate.latitude);
double lon1 = DegreesToRadians(self.coordinate.longitude);
double lat2 = DegreesToRadians(destinationLocation.coordinate.latitude);
double lon2 = DegreesToRadians(destinationLocation.coordinate.longitude);
double dLon = lon2 - lon1;
double y = sin(dLon) * cos(lat2);
double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dLon);
double radiansBearing = atan2(y, x);
return RadiansToDegrees(radiansBearing);
}