zoukankan      html  css  js  c++  java
  • IOS 定位 单例

    + (SCLocationController *)sharedController
    {
         static SCLocationController *sharedController = nil;
         static dispatch_once_t onceToken;
         dispatch_once(&onceToken, ^{
            sharedController = [[self alloc]init];
      });
    
      return sharedController;
    }
    
    - (id)init
    {
         self = [super init];
         if (self) {
            _locationManager = [[CLLocationManager alloc]init];
            _locationManager.delegate = self;
            _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
            _locationManager.distanceFilter = 30; // Meters.
      }
      return self;
    }
    
    #pragma mark - Location Manager
    #pragma mark - CLLocationManagerDelegate
    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
        [_locManager stopUpdatingLocation]; 
    
        CLGeocoder *reverseGeocoder=[[CLGeocoder alloc]  init];
        [reverseGeocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *array, NSError *error)
         {
             CLPlacemark *placeMark = [array lastObject];
             if (placeMark != nil)
             {
                 state = [placeMark.addressDictionary objectForKey:@"State"];  
                 city = [placeMark.addressDictionary objectForKey:@"City"];                   
                 subLocality = [placeMark.addressDictionary objectForKey:@"SubLocality"]; 
                 
                 if (city.length >  0) {
                     NSLog(@"%@-%@-%@",state,city,subLocality);
                 }
                 else{
                     NSLog(@"%@-%@",state,subLocality);
                 }
                 
             }
     
         }];
    }
    

      

  • 相关阅读:
    Qt计算器开发(三):执行效果及项目总结
    [HNOI2019]校园旅行
    How to fix nuget Unrecognized license type MIT when pack
    How to fix nuget Unrecognized license type MIT when pack
    git 通过 SublimeMerge 处理冲突
    git 通过 SublimeMerge 处理冲突
    git 上传当前分支
    git 上传当前分支
    gif 格式
    gif 格式
  • 原文地址:https://www.cnblogs.com/joesen/p/3698630.html
Copyright © 2011-2022 走看看