zoukankan      html  css  js  c++  java
  • iOS下获取用户当前位置的信息

    #import <MapKit/MKMapView.h>
    
    @interface ViewController (){
        CLLocationManager *_currentLoaction;
        CLGeocoder *_geocoder;
        CLPlacemark *_placeMark;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    	// Do any additional setup after loading the view, typically from a nib.
        _geocoder = [[CLGeocoder alloc] init];
        
        _currentLoaction = [[CLLocationManager alloc] init];
        _currentLoaction.delegate = self;
        [_currentLoaction startUpdatingLocation]; 
    }
    
    #pragma mark - Location
    - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
        NSLog(@"locError:%@", error);
    }
    
    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
        CLLocationCoordinate2D locat = [newLocation coordinate];
        double lattitude = locat.latitude;
        double longitude = locat.longitude;
        CLGeocodeCompletionHandler handler = ^(NSArray *placemark, NSError *error)
        {
            for (CLPlacemark *mark in placemark) {
                NSMutableDictionary *area_dic = [mark addressDictionary];
                [area_dic setValue:[NSString stringWithFormat:@"%f", lattitude] forKeyPath:@"lattitude"];
                [area_dic setValue:[NSString stringWithFormat:@"%f", longitude] forKeyPath:@"longitude"];
                NSLog(@"area_dic is %@", area_dic);
                
                NSArray *array = [area_dic objectForKey:@"FormattedAddressLines"];
                NSString *address = [area_dic objectForKey:@"FormattedAddressLines"];
                NSLog(@"array is %@", array);
                address = [array objectAtIndex:0];
                NSLog(@"address is %@", address);
                address = [area_dic objectForKey:@"City"];
                NSLog(@"City is %@", address);
            }
        };
        [_geocoder reverseGeocodeLocation:newLocation completionHandler:handler];
    }
    
  • 相关阅读:
    Mbps、Kbps、bps、kb、mb区别和换算
    Python导入模块方法
    C# WinForm 程序免安装 .NET Framework(XP/win7/win10环境运行)
    生成缩略图
    WCF 的优势和特点
    不要在using语句中调用WCF服务
    pb getchild获取DropDownDW子窗体后进行取值
    Bootstrap后台管理模板调研
    PB调用C#编写的DLL
    PowerBuilder与嵌入浏览器交互
  • 原文地址:https://www.cnblogs.com/JayK/p/4067499.html
Copyright © 2011-2022 走看看