• <tfoot id='DFxlx'></tfoot>

    <legend id='DFxlx'><style id='DFxlx'><dir id='DFxlx'><q id='DFxlx'></q></dir></style></legend>
        <i id='DFxlx'><tr id='DFxlx'><dt id='DFxlx'><q id='DFxlx'><span id='DFxlx'><b id='DFxlx'><form id='DFxlx'><ins id='DFxlx'></ins><ul id='DFxlx'></ul><sub id='DFxlx'></sub></form><legend id='DFxlx'></legend><bdo id='DFxlx'><pre id='DFxlx'><center id='DFxlx'></center></pre></bdo></b><th id='DFxlx'></th></span></q></dt></tr></i><div id='DFxlx'><tfoot id='DFxlx'></tfoot><dl id='DFxlx'><fieldset id='DFxlx'></fieldset></dl></div>

        <small id='DFxlx'></small><noframes id='DFxlx'>

          <bdo id='DFxlx'></bdo><ul id='DFxlx'></ul>

        在 iOS4.1 上保存带有照片的地理标记信息

        时间:2023-10-03

        <i id='SgVYw'><tr id='SgVYw'><dt id='SgVYw'><q id='SgVYw'><span id='SgVYw'><b id='SgVYw'><form id='SgVYw'><ins id='SgVYw'></ins><ul id='SgVYw'></ul><sub id='SgVYw'></sub></form><legend id='SgVYw'></legend><bdo id='SgVYw'><pre id='SgVYw'><center id='SgVYw'></center></pre></bdo></b><th id='SgVYw'></th></span></q></dt></tr></i><div id='SgVYw'><tfoot id='SgVYw'></tfoot><dl id='SgVYw'><fieldset id='SgVYw'></fieldset></dl></div>
          <tbody id='SgVYw'></tbody>

        <legend id='SgVYw'><style id='SgVYw'><dir id='SgVYw'><q id='SgVYw'></q></dir></style></legend>

        <tfoot id='SgVYw'></tfoot>

        <small id='SgVYw'></small><noframes id='SgVYw'>

              • <bdo id='SgVYw'></bdo><ul id='SgVYw'></ul>
                • 本文介绍了在 iOS4.1 上保存带有照片的地理标记信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在尝试使用 iOS4.1 上的地理标签信息将照片保存到相机胶卷时遇到重大问题.我正在使用以下 ALAssetsLibrary API:

                  I am having major issues trying to save a photo to camera roll with geotag info on iOS4.1. I am using following ALAssetsLibrary API:

                  - (void)writeImageDataToSavedPhotosAlbum:(NSData *)imageData 
                                                  metadata:(NSDictionary *)metadata 
                                           completionBlock:(ALAssetsLibraryWriteImageCompletionBlock)completionBlock
                  

                  我有 GPS 坐标,我希望将照片保存为输入.不幸的是,没有文档或示例代码描述如何形成封装 GPS 坐标的元数据 NSDictionary.有人可以发布一个已知有效的示例代码吗?

                  I have the GPS coordinates that i wish to save with the photo as an input. Unfortunately, there is no documentation or sample code that describes how to form the metadata NSDictionary that encapsulates the GPS coordinates. Can somebody post a sample code that is known to work ?

                  我也尝试过使用 iPhone Exif 库将地理信息保存在 imageData 中,而不是使用元数据,但不幸的是 iPhone Exif 库正在崩溃.非常感谢任何帮助.

                  I have also tried using iPhone Exif library to save geo info in imageData rather than using metadata, but unfortunately iPhone Exif library is crashing. Any help is greatly appreciated.

                  推荐答案

                  以下代码将所有可用信息从 CLLocation 对象复制到 GPS 元数据字典的正确格式:

                  Here is code to copy all available information from a CLLocation object into the proper format for a GPS metadata dictionary:

                  - (NSDictionary *)getGPSDictionaryForLocation:(CLLocation *)location {
                      NSMutableDictionary *gps = [NSMutableDictionary dictionary];
                  
                      // GPS tag version
                      [gps setObject:@"2.2.0.0" forKey:(NSString *)kCGImagePropertyGPSVersion];
                  
                      // Time and date must be provided as strings, not as an NSDate object
                      NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
                      [formatter setDateFormat:@"HH:mm:ss.SSSSSS"];
                      [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
                      [gps setObject:[formatter stringFromDate:location.timestamp] forKey:(NSString *)kCGImagePropertyGPSTimeStamp];
                      [formatter setDateFormat:@"yyyy:MM:dd"];
                      [gps setObject:[formatter stringFromDate:location.timestamp] forKey:(NSString *)kCGImagePropertyGPSDateStamp];
                      [formatter release];
                  
                      // Latitude
                      CGFloat latitude = location.coordinate.latitude;
                      if (latitude < 0) {
                          latitude = -latitude;
                          [gps setObject:@"S" forKey:(NSString *)kCGImagePropertyGPSLatitudeRef];
                      } else {
                          [gps setObject:@"N" forKey:(NSString *)kCGImagePropertyGPSLatitudeRef];
                      }
                      [gps setObject:[NSNumber numberWithFloat:latitude] forKey:(NSString *)kCGImagePropertyGPSLatitude];
                  
                      // Longitude
                      CGFloat longitude = location.coordinate.longitude;
                      if (longitude < 0) {
                          longitude = -longitude;
                          [gps setObject:@"W" forKey:(NSString *)kCGImagePropertyGPSLongitudeRef];
                      } else {
                          [gps setObject:@"E" forKey:(NSString *)kCGImagePropertyGPSLongitudeRef];
                      }
                      [gps setObject:[NSNumber numberWithFloat:longitude] forKey:(NSString *)kCGImagePropertyGPSLongitude];
                  
                      // Altitude
                      CGFloat altitude = location.altitude;
                      if (!isnan(altitude)){
                          if (altitude < 0) {
                              altitude = -altitude;
                              [gps setObject:@"1" forKey:(NSString *)kCGImagePropertyGPSAltitudeRef];
                          } else {
                              [gps setObject:@"0" forKey:(NSString *)kCGImagePropertyGPSAltitudeRef];
                          }
                          [gps setObject:[NSNumber numberWithFloat:altitude] forKey:(NSString *)kCGImagePropertyGPSAltitude];
                      }
                  
                      // Speed, must be converted from m/s to km/h
                      if (location.speed >= 0){
                          [gps setObject:@"K" forKey:(NSString *)kCGImagePropertyGPSSpeedRef];
                          [gps setObject:[NSNumber numberWithFloat:location.speed*3.6] forKey:(NSString *)kCGImagePropertyGPSSpeed];
                      }
                  
                      // Heading
                      if (location.course >= 0){
                          [gps setObject:@"T" forKey:(NSString *)kCGImagePropertyGPSTrackRef];
                          [gps setObject:[NSNumber numberWithFloat:location.course] forKey:(NSString *)kCGImagePropertyGPSTrack];
                      }
                  
                      return gps;
                  }
                  

                  将此方法返回的字典指定为您传递给 writeImageDataToSavedPhotosAlbum:metadata:completionBlock:CGImageDestinationAddImage().

                  Assign the dictionary returned by this method as the value for the kCGImagePropertyGPSDictionary key in the metadata dictionary you pass to writeImageDataToSavedPhotosAlbum:metadata:completionBlock: or CGImageDestinationAddImage().

                  这篇关于在 iOS4.1 上保存带有照片的地理标记信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:iOS 中的精确计时 下一篇:如何在 iPhone 中以编程方式将图像旋转 90 度?

                  相关文章

                  <tfoot id='5Z4Ll'></tfoot>

                  <legend id='5Z4Ll'><style id='5Z4Ll'><dir id='5Z4Ll'><q id='5Z4Ll'></q></dir></style></legend>
                • <small id='5Z4Ll'></small><noframes id='5Z4Ll'>

                    <i id='5Z4Ll'><tr id='5Z4Ll'><dt id='5Z4Ll'><q id='5Z4Ll'><span id='5Z4Ll'><b id='5Z4Ll'><form id='5Z4Ll'><ins id='5Z4Ll'></ins><ul id='5Z4Ll'></ul><sub id='5Z4Ll'></sub></form><legend id='5Z4Ll'></legend><bdo id='5Z4Ll'><pre id='5Z4Ll'><center id='5Z4Ll'></center></pre></bdo></b><th id='5Z4Ll'></th></span></q></dt></tr></i><div id='5Z4Ll'><tfoot id='5Z4Ll'></tfoot><dl id='5Z4Ll'><fieldset id='5Z4Ll'></fieldset></dl></div>
                      • <bdo id='5Z4Ll'></bdo><ul id='5Z4Ll'></ul>