【问题标题】:Arrow to point particular location in iPad箭头指向 iPad 中的特定位置
【发布时间】:2013-10-10 03:48:03
【问题描述】:

我必须根据当前位置将箭头指向特定位置。为此,我使用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?

【问题讨论】:

    标签: ios ipad cllocationmanager


    【解决方案1】:

    检查设备是ipad还是iphone并相应地编写代码

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
         // The device is an iPad running iPhone 3.2 or later.
    }
    else
    {
         // The device is an iPhone or iPod touch.
    }
    

    【讨论】:

    • 我能做到。但是上面的代码在 iPad 上不起作用。我正在寻找一个也可以在 iPad 上运行的代码。
    • 你能把任何屏幕截图放在 iPhone 和 iPad 上显示的不同吗
    最近更新 更多