상단에 위치 관리자의 대리자 메서드에 .H 파일
float GeoAngle;
이
#define RadiansToDegrees(radians)(radians * 180.0/M_PI)
#define DegreesToRadians(degrees)(degrees * M_PI/180.0)
정의합니다 변수를 정의 : -
-(float)setLatLonForDistanceAndAngle:(CLLocation *)userlocation
{
float lat1 = DegreesToRadians(userlocation.coordinate.latitude);
float lon1 = DegreesToRadians(userlocation.coordinate.longitude);
float lat2 = DegreesToRadians(locLat);
float lon2 = DegreesToRadians(locLon);
float dLon = lon2 - lon1;
float y = sin(dLon) * cos(lat2);
float x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dLon);
float radiansBearing = atan2(y, x);
if(radiansBearing < 0.0)
{
radiansBearing += 2*M_PI;
}
return radiansBearing;
}
GeoAngle 변수에서 각도가 계속 업데이트됩니다. 화살표를 대상 위치로 회전하려면 화살표 이미지를 사용하여 arrowImageView의 IBOutlet에 할당하고 머리글 업데이트 메서드에서이 옵션을 회전합니다.
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
float direction = -newHeading.trueHeading;
arrowImageView.transform=CGAffineTransformMakeRotation((direction* M_PI/180)+ GeoAngle);
}
보기 [이 (http://stackoverflow.com/questions/6745131/how-can-we-find-the-angle-between-two-locations-defined-by-latitude-or-longitude) 그리고 [this] (http://www.movable-type.co.uk/scripts/latlong.html) 참조 –