蓝懿 iOS 技术交流和心得分享 12.23

位置编解码

#import "ViewController.h"

#import

@interface ViewController ()

@property (nonatomic, strong) CLGeocoder *geocoder;

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    self.geocoder = [[CLGeocoder alloc]init];

//   [self geoCodeWithCityName:@"天津"];

    //输入请维度

    [self reverseGeocodeWithLatitude:39 andLongtitude:116];

}

- (void)geoCodeWithCityName:(NSString *)name

{

    // 开始编码

    [self.geocoder geocodeAddressString:namecompletionHandler:^(NSArray *placemarks, NSError *error) {

        if (error || placemarks.count == 0) {

            NSLog(@"找不到位置");

        } else { // 编码成功(找到了具体的位置信息)

            // 输出查询到的所有地标信息

            for (CLPlacemark *placemark in placemarks) {

                NSLog(@"name=%@ locality=%@ country=%@ postalCode=%@", placemark.name, placemark.locality, placemark.country, placemark.postalCode);

            }

            // 显示最前面的地标信息

            CLPlacemark *firstPlacemark = [placemarks firstObject];

     

            

            CLLocationDegrees latitude = firstPlacemark.location.coordinate.latitude;

            CLLocationDegrees longitude = firstPlacemark.location.coordinate.longitude;

                   NSLog(@"fistPlace = %@  经度:%f 维度%f",firstPlacemark.name,longitude,latitude);

        }

    }];

}

- (void)reverseGeocodeWithLatitude:(double )latitude andLongtitude:(double)longtitude

{

    // 开始反向编码

    CLLocation *location = [[CLLocation alloc]initWithLatitude:latitude longitude:longtitude];

    [self.geocoder reverseGeocodeLocation:locationcompletionHandler:^(NSArray *placemarks, NSError *error) {

        if (error || placemarks.count == 0) {

            NSLog(@"位置不存在");

        } else { 

   CLPlacemark *placemark = [placemarks objectAtIndex:0];

             

             

             

             

             NSLog(@"%@",placemark.name);

             //获取城市

             NSString *city = placemark.locality;

             if (!city) {

                 

                 //四大直辖市的城市信息无法通过locality获得,只能通过获取省份的方法来获得(如果city为空,则可知为直辖市)

                 

                 city = placemark.administrativeArea;

                 

             }

             

 

             NSLog(@"城市:%@",city);

*************// 编码成功(找到了具体的位置信息)

            // 输出查询到的所有地标信息

            for (CLPlacemark *placemark in placemarks) {

                NSLog(@"name=%@ locality=%@ country=%@ postalCode=%@", placemark.name, placemark.locality, placemark.country, placemark.postalCode);

            }

            // 显示最前面的地标信息

            CLPlacemark *firstPlacemark = [placemarks firstObject];

            

            CLLocationDegrees latitude = firstPlacemark.location.coordinate.latitude;

            CLLocationDegrees longitude = firstPlacemark.location.coordinate.longitude;

                 NSLog(@"fistPlace = %@  经度:%f 维度%f",firstPlacemark.name,longitude,latitude);

        }

    }];

}

interface ViewController ()<</span>UINavigationControllerDelegate, UIImagePickerControllerDelegate>

@property (nonatomic,strong)UIScrollView * sv;

@property (nonatomic,strong)NSMutableArray * images;

@end

@implementation ViewController

- (IBAction)clicked:(UIButton *)sender {

   

     self.images= [NSMutableArray array];

    UIImagePickerController * ipc = [[UIImagePickerController alloc]init];

    ipc.delegate = self;

   //是否要编辑,默认关闭的

   //ipc.allowsEditing = YES;

    [self presentViewController:ipc animated:YEScompletion:nil];

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<<span style="font-variant-ligatures: no-common-ligatures; color: #703daa">NSString *,id> *)info{

    //返回的info为一个字典,可以直接输出

  //  NSLog(@"%@",info);

    //选取UIImagePickerControllerOriginalImage等价一个字符串

   // NSLog(@"%@----%@",UIImagePickerControllerOriginalImage,@"UIImagePickerControllerOriginalImage");

    //返回未编辑图片  用UIImagePickerControllerOriginalImage  编辑的用UIImagePickerControllerEditedImage  可以选择相机来获取

    UIImage * image = info[UIImagePickerControllerOriginalImage];

    UIImageView *iv = [[UIImageViewalloc]initWithFrame:CGRectMake(80*self.images.count,0, 80,80)];

    iv.image = image;

    iv.userInteractionEnabled = YES;

   [self.sv addSubview:iv];

    UIButton * btn = [[UIButtonalloc]initWithFrame:CGRectMake(60, 0, 20, 20)];

    [btn setTitle:@"x" forState:UIControlStateNormal];

    [btn addTarget:self action:@selector(deleteAction:)forControlEvents:UIControlEventTouchUpInside];

    [iv addSubview:btn];

    

    [self.images addObject:iv];

    NSLog(@"%ld",self.images.count);

    [self.sv setContentSize:CGSizeMake(self.images.count*80,0)];

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

}

- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController*)viewController animated:(BOOL)animated{

    if (navigationController.viewControllers.count==2) {

        UIView * v = [[UIView alloc]initWithFrame:CGRectMake(0,567, 375, 80)];

        v.backgroundColor = [UIColor greenColor];

        [viewController.view addSubview:v];

        UIButton * btn = [[UIButtonalloc]initWithFrame:CGRectMake(300,0, 75, 20)];

        [btn setBackgroundColor:[UIColor blueColor]];

        [btn setTitle:@"Done" forState:UIControlStateNormal];

        [btn  addTarget:self action:@selector(backAction:)forControlEvents:UIControlEventTouchUpInside];

        v.userInteractionEnabled =YES;

        [v addSubview:btn];

        

        self.sv = [[UIScrollViewalloc]initWithFrame:CGRectMake(0, 20, 375, 80)];

        self.sv.backgroundColor = [UIColor blueColor];

        [v addSubview:self.sv];

    }

}

​学习ios  重要还是要理清楚思路  在做或者看老师代码的时候 自己多想想为什么  不要自己看着就抄       另外还是要推荐一下 蓝懿IOS这个培训机构  和刘国斌老师刘国斌老师还是很有名气的,听朋友说刘老师成立了蓝懿iOS,,老师讲课方式很独特,能够尽量让每个人都能弄明白,有的比较难懂的地方,如果有的地方还是不懂得话,老师会换个其它方法再讲解,这对于我们这些学习iOS的同学是非常好的,多种方式的讲解会理解得更全面,这个必须得给个赞,嘻嘻,还有就是这里的学习环境很好,很安静,可以很安心的学习,安静的环境是学习的基础,小班讲课,每个班20几个学生,学习氛围非常好,每天都学到9点多才离开教室,练习的时间很充裕,而且如果在练习的过程中有什么困难,随时可以向老师求助,不像其它机构,通过视频教学,有的甚至学完之后都看不到讲师本人,问点问题都不方便,这就是蓝懿与其它机构的区别,相信在刘国斌老师的细心指导下,每个蓝懿学员都能找到满意的工作,加油!

                                                                  写博客第七十四天;

                                                                              QQ:565803433

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值