直接上代码:

//
//  ViewController.m
//  changeLocation
//
//  Created by 陈飞 on 16/10/31.
//  Copyright © 2016年 liusong. All rights reserved.
//

#import "ViewController.h"
#import "UploadImageView.h"
#import "UIToast.h"

@interface ViewController ()
    @property (weak, nonatomic) IBOutlet UITextField *longitude;
    @property (weak, nonatomic) IBOutlet UITextField *latitude;

    @end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)change:(id)sender {

    if (self.longitude.text.length<=0||self.latitude.text.length<=0) {
        [UIToast showMessage:@"请输入经纬度"];
        return;
    }
    //浮点数值使用CGFloat,NSDecimalNumber对象进行处理:
    NSDecimalNumber *longitude = [[NSDecimalNumber alloc] initWithString:self.longitude.text];
    NSDecimalNumber *latitude = [[NSDecimalNumber alloc] initWithString:self.latitude.text];

    [UploadImageView showUpUploadImageViewWithBlockImage:^(UIImage *newImage) {

    } longitude:[longitude doubleValue ] latitude:[latitude doubleValue ]];
}
@end

图像处理类M:

//
//  UploadImageView.m
//  kuaichengwuliu
//
//  Created by 陈飞 on 16/4/30.
//  Copyright © 2016年 kuaicheng. All rights reserved.
//

#import "UploadImageView.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import <ImageIO/ImageIO.h>
#import "UIToast.h"
@interface UploadImageView () <
    UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate,
    UIImagePickerControllerDelegate, UIGestureRecognizerDelegate,
    UIActionSheetDelegate>

@property(nonatomic, weak) UITableView *tableView;
@property(nonatomic, strong) NSArray *contents;
@property(nonatomic, assign) int index;
@property(nonatomic,strong)NSMutableDictionary* mediaInfo;//当前照片的mediaInfo

@property(nonatomic,strong) UIImage *image;

    @property (nonatomic,assign) CGFloat longitude;
@property (nonatomic,assign) CGFloat latitude;
@end
@implementation UploadImageView

+ (void)showUpUploadImageViewWithBlockImage:(BlockImage)blockImage longitude:(CGFloat)longitude latitude:(CGFloat)latitude {

  UploadImageView *v = [[UploadImageView alloc] init];
    v.longitude=longitude;
    v.latitude=latitude;
  [[UIApplication sharedApplication].keyWindow addSubview:v];
  v.clickBlockImage = blockImage;
  if ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0) {
    UIAlertController *alert = [UIAlertController
        alertControllerWithTitle:@"请选择"
                         message:nil
                  preferredStyle:(UIAlertControllerStyleActionSheet)];
    UIAlertAction *action1 = [UIAlertAction
        actionWithTitle:@"相册"
                  style:(UIAlertActionStyleDefault)
                handler:^(UIAlertAction *_Nonnull action) {
                  UIImagePickerController *picker =
                      [[UIImagePickerController alloc] init];
                  picker.delegate = v;
                  picker.sourceType =
                      UIImagePickerControllerSourceTypePhotoLibrary;
                  [[UIApplication sharedApplication]
                          .keyWindow.rootViewController
                      presentViewController:picker
                                   animated:YES
                                 completion:nil];

                }];
    UIAlertAction *action2 = [UIAlertAction
        actionWithTitle:@"拍照"
                  style:(UIAlertActionStyleDefault)
                handler:^(UIAlertAction *_Nonnull action) {
                  UIImagePickerController *picker =
                      [[UIImagePickerController alloc] init];
                  picker.delegate = v;
                  picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                  [[UIApplication sharedApplication]
                          .keyWindow.rootViewController
                      presentViewController:picker
                                   animated:YES
                                 completion:nil];
                }];
    UIAlertAction *action3 =
        [UIAlertAction actionWithTitle:@"取消"
                                 style:(UIAlertActionStyleCancel)
                               handler:^(UIAlertAction *_Nonnull action) {
                                 [v removeFromSuperview];

                               }];
    [alert addAction:action1];
    [alert addAction:action2];
    [alert addAction:action3];
    [[UIApplication sharedApplication]
            .keyWindow.rootViewController presentViewController:alert
                                                       animated:YES
                                                     completion:nil];
  } else {
    UIActionSheet *sheet =
        [[UIActionSheet alloc] initWithTitle:@"请选择"
                                    delegate:v
                           cancelButtonTitle:@"取消"
                      destructiveButtonTitle:nil
                           otherButtonTitles:@"相册", @"拍照", nil];
    [sheet showInView:[UIApplication sharedApplication]
                          .keyWindow.rootViewController.view];
  }
}

- (void)actionSheet:(UIActionSheet *)actionSheet
    clickedButtonAtIndex:(NSInteger)buttonIndex {
  UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  picker.delegate = self;

  if (buttonIndex == 0) {
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [[UIApplication sharedApplication]
            .keyWindow.rootViewController presentViewController:picker
                                                       animated:YES
                                                     completion:nil];
  } else if (buttonIndex == 1) {

    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [[UIApplication sharedApplication]
            .keyWindow.rootViewController presentViewController:picker
                                                       animated:YES
                                                     completion:nil];
  } else if (buttonIndex == 2) {
    [self removeFromSuperview];
  }
}

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info {

    NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
     UIImage *image = info[UIImagePickerControllerOriginalImage];
    self.image=image;
     self.mediaInfo=[NSMutableDictionary dictionaryWithDictionary:info];

//    GPS setValue:@"25.271139" forKey:kCGImagePropertyGPSLatitude];
//    [GPS setValue:@"55.30748500000004" for/
    [self  log:info];

//    [self write];
  [picker dismissViewControllerAnimated:YES completion:nil];

  if (!image) {
    [self removeFromSuperview];
    return;
  }
  if (self.clickBlockImage) {
    self.clickBlockImage(image);
  }
  [self removeFromSuperview];

}
-(void)log:(NSDictionary*)info
{
    NSLog(@"info:%@",info);
    __block NSMutableDictionary *imageMetadata = nil;
    NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library assetForURL:assetURL
             resultBlock:^(ALAsset *asset)  {
                 imageMetadata = [[NSMutableDictionary alloc] initWithDictionary:asset.defaultRepresentation.metadata];
                 //控制台输出查看照片的metadata
                 NSLog(@"2222222-------%@",imageMetadata);
                 self.mediaInfo=imageMetadata;
                 [self write];
                 //GPS数据
                 NSDictionary *GPSDict=[imageMetadata objectForKey:(NSString*)kCGImagePropertyGPSDictionary];
                 if (GPSDict!=nil) {

                 }
                 else{

                 }

                 //EXIF数据
                 NSMutableDictionary *EXIFDictionary =[[imageMetadata objectForKey:(NSString *)kCGImagePropertyExifDictionary]mutableCopy];
                 NSString * dateTimeOriginal=[[EXIFDictionary objectForKey:(NSString*)kCGImagePropertyExifDateTimeOriginal] mutableCopy];
                 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
                 [dateFormatter setDateFormat:@"yyyy:MM:dd HH:mm:ss"];//yyyy-MM-dd HH:mm:ss
                 NSDate *date = [dateFormatter dateFromString:dateTimeOriginal];
             }
            failureBlock:^(NSError *error) {
            }];

}

-(void)write
{
    //获取照片元数据
    NSDictionary *dict = [_mediaInfo objectForKey:UIImagePickerControllerMediaMetadata];
    NSMutableDictionary *metadata = [NSMutableDictionary dictionaryWithDictionary:dict];
    NSLog(@"111111111111-----%@",dict);
    //将GPS数据写入图片并保存到相册

    NSTimeZone    *timeZone   = [NSTimeZone timeZoneWithName:@"UTC"];
    NSDateFormatter *formatter  = [[NSDateFormatter alloc] init];
    [formatter setTimeZone:timeZone];
    [formatter setDateFormat:@"HH:mm:ss.SS"];

//    CGFloat longitude=54.317147;
//    CGFloat latitude=24.461780;
    CGFloat longitude=self.longitude;
    CGFloat latitude=self.latitude;
    NSString * timeStamp=[_mediaInfo objectForKey:(NSString*)kCGImagePropertyGPSTimeStamp];
    NSDate *timeDate=[formatter dateFromString:timeStamp];

    NSDictionary *gpsDict   = [NSDictionary dictionaryWithObjectsAndKeys:
                               [NSNumber numberWithDouble :fabs(latitude)], kCGImagePropertyGPSLatitude,
                               ((latitude >= 0) ? @"N" : @"S"), kCGImagePropertyGPSLatitudeRef,
                               [NSNumber numberWithDouble:fabs(longitude)], kCGImagePropertyGPSLongitude,
                               ((longitude >= 0) ? @"E" : @"W"), kCGImagePropertyGPSLongitudeRef,
                               [formatter stringFromDate:timeDate], kCGImagePropertyGPSTimeStamp,
                               nil];

    if (metadata&& gpsDict) {
        [metadata setValue:gpsDict forKey:(NSString*)kCGImagePropertyGPSDictionary];
    }
    [self writeCGImage:_image metadata:metadata];
}
    /*
     保存图片到相册
     */
- (void)writeCGImage:(UIImage*)image metadata:(NSDictionary *)metadata{
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    ALAssetsLibraryWriteImageCompletionBlock imageWriteCompletionBlock =
    ^(NSURL *newURL, NSError *error) {
        if (error) {
            [UIToast showMessage:@"改变失败"];
            NSLog( @"Error writing image with metadata to Photo Library: %@", error );
        } else {
            [UIToast showMessage:@"改变成功"];
            NSLog( @"Wrote image with metadata to Photo Library");
        }
    };

    //保存相片到相册 注意:必须使用[image CGImage]不能使用强制转换: (__bridge CGImageRef)image,否则保存照片将会报错
    [library writeImageToSavedPhotosAlbum:[image CGImage]
                                 metadata:metadata
                          completionBlock:imageWriteCompletionBlock];

}

//+ (void)showUpUploadImageViewWithBlockImage:(BlockImage)blockImage
//{
//
//  UploadImageView *view = [[UploadImageView alloc] init];
//    view.clickBlockImage=blockImage;
//
//  UIView *window = [UIApplication sharedApplication] .keyWindow;
//
//    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]
//                                 initWithTarget:view
//                                 action:@selector(dismiss)];
//    tap.delegate=view;
//  [view addGestureRecognizer:tap];
//
//  view.backgroundColor = [UIColor colorWithWhite:0.000 alpha:0.204];
//  view.frame = window.bounds;
//    view.contents=@[@"拍照",@"从相册中选择"];
//  [window addSubview:view];
//
//  UITableView *tableView =
//      [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)
//                                   style:UITableViewStylePlain];
//    tableView.layer.cornerRadius=5;
//    tableView.layer.masksToBounds=YES;
//  tableView.width = view.width * 3 / 5;
// tableView.height = view.contents.count * 44;
//  tableView.center = view.center;
//  tableView.delegate = view;
//  tableView.dataSource = view;
//  view.tableView = tableView;
//    [view addSubview:tableView];
//
//  view.alpha = 0;
//  tableView.alpha = 0;
//  [UIView animateWithDuration:0.25
//                   animations:^{
//                     view.alpha = 1;
//                     tableView.alpha = 1;
//                   }];
//}
//- (NSInteger)tableView:(UITableView *)tableView
// numberOfRowsInSection:(NSInteger)section {
//  return 2;
//}
//- (UITableViewCell *)tableView:(UITableView *)tableView
//         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//  TipPlainCell *cell =
//      [TipPlainCell tipPlainCellWithTableView:tableView];
//    cell.textLabel.text = self.contents[indexPath.row];
//  return cell;
//}
//-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
//*)indexPath
//{
//    self.alpha=0;
//    UIImagePickerController *picker=[[UIImagePickerController alloc]init];
//    picker.delegate=self;
//    if (indexPath.row==0) {
//        picker.sourceType=UIImagePickerControllerSourceTypeCamera;
//    }else{
//    picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
//    }
//
//    [[UIApplication sharedApplication].keyWindow.rootViewController
//    presentViewController:picker animated:YES completion:nil];
//
//}

//- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
//{
//    [picker dismissViewControllerAnimated:YES completion:nil];
//    [self removeFromSuperview];
//}
//-(void)dealloc
//{
//    NSLog(@"dealloc");
//
//
//}
///// 消失
//-(void)dismiss
//{
//    [UIView animateWithDuration:0.25 animations:^{
//        self.alpha = 0;
//
//    }completion:^(BOOL finished) {
//        [self removeFromSuperview];
//        for (UIView *v in self.subviews) {
//            [v removeFromSuperview];
//        }
//
//    }];
//}
//#pragma mark -UIGestureRecognizerDelegate
//-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
//shouldReceiveTouch:(UITouch *)touch
//{
//    if ([NSStringFromClass([touch.view class])
//    isEqualToString:@"UITableViewCellContentView"]) {
//        return NO;
//    }
//    return YES;
//}
@end

以上!。

//
//  ViewController.m
//  changeLocation
//
//  Created by 陈飞 on 16/10/31.
//  Copyright © 2016年 liusong. All rights reserved.
//

#import "ViewController.h"
#import "UploadImageView.h"
#import "UIToast.h"

@interface ViewController ()
    @property (weak, nonatomic) IBOutlet UITextField *longitude;
    @property (weak, nonatomic) IBOutlet UITextField *latitude;
    
    @end

@implementation ViewController
    
- (void)viewDidLoad {
    [super viewDidLoad];

}
    
    
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)change:(id)sender {
    
    if (self.longitude.text.length<=0||self.latitude.text.length<=0) {
        [UIToast showMessage:@"请输入经纬度"];
        return;
    }
    //浮点数值使用CGFloat,NSDecimalNumber对象进行处理:
    NSDecimalNumber *longitude = [[NSDecimalNumber alloc] initWithString:self.longitude.text];
    NSDecimalNumber *latitude = [[NSDecimalNumber alloc] initWithString:self.latitude.text];

[UploadImageView showUpUploadImageViewWithBlockImage:^(UIImage *newImage) {
        
    } longitude:[longitude doubleValue ] latitude:[latitude doubleValue ]];
}
@end

IOS 修改图片的地理位置信息的更多相关文章

  1. IOS: 使用imageIO获取和修改图片的exif信息

    使用imageIO获取和修改图片的exif信息 一幅图片除了包含我们能看见的像素信息,背后还包含了拍摄时间,光圈大小,曝光等信息.UIImage类将这些细节信息都隐藏了起来,只提供我们关心的图片尺寸, ...

  2. iOS 关于图片地理位置隐私信息的分析和读取

    今天突然想到微信朋友圈发照片,涉及个人隐私的地理位置是否外泄.因为iphone拍照的照片都会带有地理位置等信息,我们先来实现怎么读取里面的安全信息,然后再来分析 #import "ViewC ...

  3. 使用ueditor时候修改图片路径及其相关信息

    ueditor功能比较强大  使用也比较方便 但是有一些东西是需要我们自己根据实际情况去设置的 以下是关于图片/涂鸦/视频等上传信息的更改: 首先我们要找到配置文件config.json 注意不是co ...

  4. iOS开发:iOS中图片与视频一次性多选 - v2m

    一.使用系统的Assets Library Framework这个是用来访问Photos程序中的图片和视频的库.其中几个类解释如下 ALAsset ->包含一个图片或视频的各种信息 ALAsse ...

  5. 利用Photoshop修改图片以达到投稿要求

    摘自:http://www.dxy.cn/bbs/thread/8602152#8602152 利用Photoshop修改图片以达到投稿要求 软件版本为Photoshop CS V8.0.1(中文版) ...

  6. ios 定位获取当前位置信息

    啊,倦怠的人生啊~~ 什么事情都没做一眨眼就2点半了啊!!赶紧爬起来写博客啊. 诸位看官会鄙视我么,表示我真心不是把这当技术文章写的啊. 啊,下午我们来第二篇.获取地理位置信息.嗯嗯,秘籍上说叫逆向地 ...

  7. 项目源码--JAVA基于LBS地理位置信息应用的服务端

    技术要点: 1. LBS应用框架服务端实现 2. JAVA服务端技术 3. MYSQL数据库技术 4. 源码带详细的中文注释 ......   详细介绍: 1. LBS应用框架服务端实现 此套源码是基 ...

  8. FLAnimatedImage -ios gif图片加载框架介绍

    简介 FLAnimatedImage 是 Flipboard 团队开发的在它们 App 中渲染 GIF 图片使用的库. 后来 Flipboard 将 FLAnimatedImage 开源出来供大家使用 ...

  9. AngularJS进阶(二十)HTML5实现获取地理位置信息并定位功能

    HTML5实现获取地理位置信息并定位功能 注:请点击此处进行充电! 前言 这篇文章主要介绍了HTML5实现获取地理位置信息并定位功能,本文讲解了原生HTML5.百度地图.谷歌地图等三种获取理位置信息并 ...

随机推荐

  1. Spring Boot学习总结二

    Redis是目前业界使用最广泛的内存数据存储.相比memcached,Redis支持更丰富的数据结构,例如hashes, lists, sets等,同时支持数据持久化.除此之外,Redis还提供一些类 ...

  2. Ubuntu18.04关机卡死问题

    直接进入正题!你的电脑卡死说明带有独显!而Ubuntu默认是不给你的显卡装驱动的,那这就导致关机卡死的问题.按住键盘Ctrl+Alt+T打开终端,输入下面的命令 software-properties ...

  3. Evaluation of Forwarding Efficiency in NFV-Nodes Toward Predictable Service Chain Performance

    文章名称:Evaluation of Forwarding Efficiency in NFV-Nodes Toward Predictable Service Chain Performance 发 ...

  4. 【sql server】“因为数据库正在使用,所以无法获得对数据库的独占访问权” 解决方案汇总

    #事故现场: 在尝试还原数据库时,出现如下错误: #方案一:设置数据库在单用户模式下工作: 1.数据库上右键“属性”: 2.“选项”->“限制访问”,选择“SINGLE_USER” 3.还原数据 ...

  5. 2018-2019-2 《Java程序设计》第9周学习总结

    20175319 2018-2019-2 <Java程序设计>第9周学习总结 教材学习内容总结 本周学习任务: 下载安装MySQL数据库管理系统. 教材介绍在官网下载安装Mysql服务,启 ...

  6. JGUI源码:prefixfree 这个库有时候会引起网页一直加载中(10)

    如题,大部分情况下正常,但是chrome频繁刷新时,会出现这个问题,控制台没有异常信息.最终放弃使用引用第三方库prefixfree.min.js

  7. IntelliJ IDEA 的默认文件编码

    建好项目,首先注意改项目默认编码 File->Settings(快捷键Ctrl+Alt+S)->Editor->File Encodings File->Other Setti ...

  8. QT背景颜色,菜单颜色更改

    1.进入QT上置菜单栏 工具->选项 2.进入选项中 环境->interface (1)颜色:点击重置是默认颜色,想修改其他颜色,点击重置旁边的颜色自行选择. (2)Theme:这个里面提 ...

  9. Mybatis的缓存

    1.缓存是什么 在 Mybatis 里面,所谓的缓存就是将已经查询过的记录放在内存的缓冲区或文件上,这样如果再次查询,可以通过配置的策略,命中已经查询过的记录,从而提高查询的效率. Mybatis 的 ...

  10. Luogu CF451E Devu and Flowers 题解报告

    题目传送门 [题目大意] 有n种颜色的花,第i种颜色的花有a[i]朵,从这些花中选m朵出来,问有多少种方案?答案对109+7取模 [思路分析] 这是一个多重集的组合数问题,答案就是:$$C_{n+m- ...