我必须根据当前位置将箭头指向特定位置。为此,我使用didUpdateHeading
委托方法来获取真正的标题值。
在 iPhone(纵向模式)中,箭头图像完美显示。但在 iPad 中它不能正确显示。它处于横向模式。
我用来查找方位距离的代码是,
- (void)UpdateCompass:(NSNotification *)notification
{
CLLocation *newLocation = [[CLLocation alloc] initWithLatitude:m_nLatitude longitude:m_nLongitude];
CLLocation* target = [[CLLocation alloc] initWithLatitude:questionLatitude longitude:questionLangitude ];
_latestBearing = [self getHeadingForDirectionFromCoordinate:newLocation.coordinate toCoordinate:target.coordinate];
CGFloat degrees = _latestBearing - m_CLHeading.magneticHeading;
CGAffineTransform cgaRotate = CGAffineTransformMakeRotation([self degreesToRadians:degrees]);
m_arrowImage.transform = cgaRotate;
}
- (double)degreesToRadians:(double)degrees
{
return degrees * M_PI / 180.0;
}
- (double)radiansToDegrees:(double)radians
{
return radians * 180.0/M_PI;
}
- (double)getHeadingForDirectionFromCoordinate:(CLLocationCoordinate2D)fromLoc toCoordinate:(CLLocationCoordinate2D)toLoc
{
double lat1 = [self degreesToRadians:fromLoc.latitude];
double lon1 = [self degreesToRadians:fromLoc.longitude];
double lat2 = [self degreesToRadians:toLoc.latitude];
double lon2 = [self degreesToRadians:toLoc.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);
if(radiansBearing < 0.0)
radiansBearing += 2*M_PI;
return [self radiansToDegrees:radiansBearing];
}
我怎样才能使它适用于 iPad?