zoukankan      html  css  js  c++  java
  • iOS 定位于地理反编码

    - (void)viewDidLoad {
    
    [self startLocation];
    }
    
    //开始定位
    -(void)startLocation{
        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.delegate = self;
        
        [self.locationManager requestWhenInUseAuthorization];
        if ([[[UIDevice currentDevice]systemVersion]doubleValue]>=8.0) {
            
            [self.locationManager requestWhenInUseAuthorization];
            [self.locationManager requestAlwaysAuthorization];
            
        }
        [self.locationManager startUpdatingLocation];
        
        if ([CLLocationManager locationServicesEnabled]) {
            self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
            self.locationManager.distanceFilter = kCLDistanceFilterNone;
        }else
        {
            NSLog(@"open fail");
        }
        
    }
    #pragma mark - CoreLocation 代理
    #pragma mark 跟踪定位代理方法,每次位置发生变化即会执行(只要定位到相应位置)
    -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
    {
        CLLocation *location=[locations lastObject];
        CLLocationCoordinate2D coordinate=location.coordinate;
        NSLog(@"经度:%f,纬度:%f",coordinate.longitude,coordinate.latitude);
        self.longitude=coordinate.longitude;
        self.latitude=coordinate.latitude;
        //如果不需要实时定位,使用完即使关闭定位服务
        [self.locationManager stopUpdatingLocation];
        [self weiZhi];
    }
    -(void)weiZhi
    {
        self.geocoder=[[CLGeocoder alloc]init];
        CLLocation *rr=[[CLLocation alloc]initWithLatitude:self.latitude longitude:self.longitude];
        [self.geocoder reverseGeocodeLocation:rr completionHandler:^(NSArray *placemarks, NSError *error) {
            
            CLPlacemark *mark=[placemarks objectAtIndex:0];
            UILabel *currentLocation=[[UILabel alloc]initWithFrame:CGRectMake(220, 15, 100, 20)];
            currentLocation.text=[NSString stringWithFormat:@"%@",mark.subLocality];
            
            [self.locationView addSubview:currentLocation];
        }];
    
    }
    -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
    {
         switch (status) {
             case kCLAuthorizationStatusNotDetermined:
             if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
             {
                 [self.locationManager requestWhenInUseAuthorization];
             }
             break;
             default:
             break;
         }
    
    
    }
    //当定位出现错误时就会调用这个方法。
    - (void)locationManager:(CLLocationManager *)manager
           didFailWithError:(NSError *)error
    {
        NSLog(@"error-%@",error);
    
    }

    定位当前的位置。对于 CLPlacemark 还有许多属性,不仅仅可以给出当前位置,还可以给出其他信息,后续研究。。。。

    淡然;敬胜怠,义胜欲;知其雄,守其雌
  • 相关阅读:
    4.异常捕获后再次抛出
    图像滤镜处理算法:灰度、黑白、底片、浮雕
    JAVA层和JNI层实现Bitmap图镜像功能。
    关于ARGB_8888、ALPHA_8、ARGB_4444、RGB_565的理解
    镜象变换的源代码
    android 图像处理(黑白,模糊,浮雕,圆角,镜像,底片,油画,灰白,加旧,哈哈镜,放大镜)
    android获取项目下的一张图片的绝对路径问题以及解决方法
    fwrite用法
    关于毁灭地球
    memset,memcpy
  • 原文地址:https://www.cnblogs.com/xblover/p/4806464.html
Copyright © 2011-2022 走看看