iphone - 度数的主要风向?

标签 iphone objective-c weather

有没有人在 Objective C 中有一些示例代码,其中风度(即 180 度变成 S(南))转换为基本风向(N、NNE、SSE、SE 等)?

最佳答案

怎么样

- (NSString *)windDirectionFromDegrees:(float)degrees
{
    static NSArray *directions;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        // Initialize array on first call.
        directions = @[@"N", @"NNE", @"NE", @"ENE", @"E", @"ESE", @"SE", @"SSE",
                       @"S", @"SSW", @"SW", @"WSW", @"W", @"WNW", @"NW", @"NNW"];
    });

    int i = (degrees + 11.25)/22.5;
    return directions[i % 16];
}

(我假设 degrees 不是负数。)

关于iphone - 度数的主要风向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13220367/

相关文章:

api - 我可以在商业项目中使用 Google Weather API 吗?

ios - 如何从 iOS 中的后台任务打开应用程序?

iphone - iOS 应用程序的应用程序委托(delegate)是否需要保留 UIWindow?

iphone - 尝试编译 MobileSubstrate 插件 - undefined symbol

ios - 无法解密AES256密文

weather - AccuWeather API 可以免费用于商业用途吗?

JQuery simpleWeather 问题

iphone - iOS - iPhone : UISlider track image disappearing randomly

iOS13 立即检查互联网连接

iphone - 使用GCD时,锁定对象的NSMutableArray而不是对象的其余部分