如何获取经纬度的时区

我需要显示的date和时间基于给定经纬度在应用程序中。 我使用Google API来获取时区ID,但它也应该脱机工作。 有没有办法获得时区而不连接到互联网?

试试这个:

CLLocation *location = [[CLLocation alloc] initWithLatitude:50.449846 longitude:30.523629]; NSTimeZone *timeZone = [[APTimeZones sharedInstance] timeZoneWithLocation:location]; NSLog(@"%@", timeZone); 

在这里find库: https : //github.com/Alterplay/APTimeZones


你也可以通过代码来完成(通过https://stackoverflow.com/a/27054583/3202193回答):

 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 = \"[az]*\\/[az]*_*[az]*\"" 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); }