从iOS相机胶卷获取图片的时区

时间:2012-12-13 08:41:05

标签: ios timezone exif alassetslibrary

我正在尝试从其EXIF数据中确定图片的时区(以UTC格式转换日期)。我试图拍照,然后检查其元数据:

{
    ColorModel = RGB;
    DPIHeight = 72;
    DPIWidth = 72;
    Depth = 8;
    Orientation = 6;
    PixelHeight = 1936;
    PixelWidth = 2592;
    "{Exif}" =     {
        ApertureValue = "2.970854";
        BrightnessValue = "-2.571174";
        ColorSpace = 1;
        ComponentsConfiguration =         (
            1,
            2,
            3,
            0
        );
        DateTimeDigitized = "2012:12:13 01:21:55";
        DateTimeOriginal = "2012:12:13 01:21:55";
        ExifVersion =         (
            2,
            2,
            1
        );
        ExposureMode = 0;
        ExposureProgram = 2;
        ExposureTime = "0.06666667";
        FNumber = "2.8";
        Flash = 16;
        FlashPixVersion =         (
            1,
            0
        );
        FocalLenIn35mmFilm = 35;
        FocalLength = "3.85";
        ISOSpeedRatings =         (
            1000
        );
        MeteringMode = 5;
        PixelXDimension = 2592;
        PixelYDimension = 1936;
        SceneCaptureType = 0;
        SensingMethod = 2;
        ShutterSpeedValue = "3.9112";
        SubjectArea =         (
            1295,
            967,
            699,
            696
        );
        WhiteBalance = 0;
    };
    "{GPS}" =     {
        Altitude = "258.794";
        AltitudeRef = 0;
        ImgDirection = "24.38477";
        ImgDirectionRef = T;
        Latitude = "45.02183333333333";
        LatitudeRef = N;
        Longitude = "7.610833333333334";
        LongitudeRef = E;
        TimeStamp = "00:21:53.87";
    };
    "{TIFF}" =     {
        DateTime = "2012:12:13 01:21:55";
        Make = Apple;
        Model = "iPhone 4";
        Orientation = 6;
        ResolutionUnit = 2;
        Software = "6.0.1";
        XResolution = 72;
        YResolution = 72;
        "_YCbCrPositioning" = 1;
    };
}

它似乎有本地时间(DateTimeOriginal)和UTC时间({GPS} - > TimeStamp),但没有关于这两个之间的偏移的指示。我可以做一些事情来确定DateTimeOriginal和TimeStamp之间的区别,但是第二个没有日期,所以在他们跨越两个不同日子的情况下似乎很棘手。

有没有办法获得完整的UTC日期,或当地时间与时区?

我还想从lat / lon数据中确定时区,但这似乎也很复杂,因为它涉及使用外部服务从坐标中获取国家。

2 个答案:

答案 0 :(得分:2)

我认为你最好的选择是使用网络服务..我认为你不能从中得到任何东西。

如果选择此选项,请查看earthtools。我听说它可能会受到时间偏移(虽然我没有看到它),但你不会在意,因为你想要的只是时区。

这很容易使用,例如,如果你想在法国巴黎(坐标48°51'44'N 2°21'03E)的时区,你打电话给这个页面:http://www.earthtools.org/timezone-1.1/40.71417/2.2103,你得到这个xml文件:

<timezone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.earthtools.org/timezone.xsd">
    <version>1.0</version>
    <location>
        <latitude>40.71417</latitude>
        <longitude>2.2103</longitude>
    </location>
    <offset>1</offset>
    <suffix>A</suffix>
    <localtime>13 Dec 2012 09:57:58</localtime>
    <isotime>2012-12-13 09:57:58 +0100</isotime>
    <utctime>2012-12-13 08:57:58</utctime>
    <dst>False</dst>
</timezone>

答案 1 :(得分:0)

能够从时间戳中获取UTC日期,但我找不到任何支持它的文档。

你可以试试这个:

//ALAsset *asset is your photo
NSDate *timestamp = (NSDate *)[asset valueForProperty:@"ALAssetPropertyDate";

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
[dateFormatter setTimeZone:timeZone];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *dateString = [dateFormatter stringFromDate:timestamp];

NSLog (@"UTC timestamp: %@", dateString);

转换自https://stackoverflow.com/a/2615847/653513