Ios 如何通过经纬度获取时区

Ios 如何通过经纬度获取时区,ios,geolocation,timezone,Ios,Geolocation,Timezone,我需要根据应用程序中给定的lat/long显示日期和时间。我使用GoogleAPI来获取时区ID,但它也可以脱机工作。有没有办法在不连接互联网的情况下获取时区?试试这个: CLLocation *location = [[CLLocation alloc] initWithLatitude:50.449846 longitude:30.523629]; NSTimeZone *timeZone

我需要根据应用程序中给定的lat/long显示日期和时间。我使用GoogleAPI来获取时区ID,但它也可以脱机工作。有没有办法在不连接互联网的情况下获取时区?

试试这个:

CLLocation *location = [[CLLocation alloc] initWithLatitude:50.449846
                                                  longitude:30.523629];

NSTimeZone *timeZone = [[APTimeZones sharedInstance] timeZoneWithLocation:location];
NSLog(@"%@", timeZone);
在此处查找库:


您也可以通过代码(回答人):


这是相关的。这也是相关的……可笑的是,这不是那个问题的重复。这是关于iOS的,这个问题首先出现在谷歌上,2019年没有好的答案(Swift,现代iOS版本)。链接的问题没有iOS的解决方案。对于APTimeZones库+1,它有时区的脱机数据库并使用它。但在某些情况下可能不准确,请查看项目的“问题”选项卡。夏令时时区更改可能会出现问题,另一种情况是,时区执行最近点查找,这通常是错误的。通过两个正方形的示意图,查看其和的部分。
CLLocation *currentLocaiton = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];

[geoCoder reverseGeocodeLocation:currentLocaiton completionHandler:^(NSArray *placemarks, NSError *error) {

    if (error == nil && [placemarks count] > 0) {

        placeMark = [placemarks lastObject];
         NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"identifier = \"[a-z]*\\/[a-z]*_*[a-z]*\"" options:NSRegularExpressionCaseInsensitive error:NULL];
        NSTextCheckingResult *newSearchString = [regex firstMatchInString:[placeMark description] options:0 range:NSMakeRange(0, [placeMark.description length])];
        NSString *substr = [placeMark.description substringWithRange:newSearchString.range];
        NSLog(@"timezone id %@",substr); 

    }