如何通过纬度和经度获得时区



我需要显示日期和时间基于给定的晚/长在应用程序。我与谷歌API工作,以获得时区ID,但它应该离线工作了。有没有办法在没有连接到互联网的情况下获得时区?

试试这个:

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

查找图书馆: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 = "[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); 
    }

相关内容

  • 没有找到相关文章

最新更新