iOS 定位
来源:互联网 发布:开源软件移植 编辑:程序博客网 时间:2024/05/16 17:23
//创建定位管理者 _locationManager = [[CLLocationManager alloc]init]; //是否开启定位 if ([CLLocationManager locationServicesEnabled]) { //是否授权 if ([CLLocationManager authorizationStatus]!=kCLAuthorizationStatusAuthorizedWhenInUse) { //申请授权 与plist文件一致 addrow (NSLocationWhenInUseUsageDescription) [_locationManager requestWhenInUseAuthorization]; }else{ //要求的精度 /* kCLLocationAccuracyBestForNavigation //导航用 kCLLocationAccuracyBest; //最好的 */ _locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; _locationManager.delegate = self; //开启定位 [_locationManager startUpdatingLocation]; _locationHud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; _locationHud.labelText = @"正在定位..."; } }#pragma mark - CLLocationManagerDelegate 代理- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ //1.停止定位 [manager stopUpdatingLocation]; //新浪反编码 /* CLLocation *location = [locations lastObject]; CLLocationCoordinate2D coordinate = location.coordinate; double latitude = coordinate.latitude; double longitude = coordinate.longitude; NSString * paramasTring = [NSString stringWithFormat:@"%f,%f",longitude,latitude]; NSDictionary *dic = @{@"coordinate":paramasTring}; [DataNetSeveice requestWithURLStr:@"location/geo/geo_to_address.json" httpMethod:@"GET" params:[dic mutableCopy] fileData:nil success:^(id result) { NSDictionary *geosDict = [result[@"geos"] lastObject]; NSString *address = geosDict[@"address"]; NSLog(@"定位成功:%@",address); } failed:^(NSError *erro) { }]; */ //iOS8 反编码 //创建地理编码对象 CLGeocoder * geoCoder = [[CLGeocoder alloc] init]; //进行反编码 [geoCoder reverseGeocodeLocation:[locations lastObject] completionHandler:^(NSArray *placemarks, NSError *error) { // NSLog(@"%@",placemarks); //地理信息 CLPlacemark *mark = [placemarks lastObject]; // NSLog(@"%@",mark); //获取存储地理位置的字典 NSDictionary *dic = mark.addressDictionary; NSString *adress = dic[@"SubLocality"];// NSLog(@"%@",adress); self.locationLabel.text = adress; [_locationLabel sizeToFit]; _locationHud.hidden = YES; //隐藏定位风火轮 }]; }
0 0
- IOS定位
- IOS定位
- IOS 定位
- iOS定位
- ios 定位
- IOS 定位
- iOS 定位
- ios定位
- iOS定位
- iOS 定位
- ios 定位
- IOS定位
- iOS 定位
- ios定位
- iOS-定位
- iOS 定位
- 【读书笔记】iOS-iOS定位
- IOS 定位系统实例
- mac下已安装的ssh的id_rsa.pub文件位置
- Writing your first Django app, part 1
- iOS UI 21 动画
- php 几个常见的加密函数
- HTTP协议
- iOS 定位
- 深度?广度?浅析技术人员的职业发展之路
- 分布式版本控制系统----GIT的使用(二)
- iOS UI 21 线程
- ios app应用换皮肤功能
- 第八周项目3-顺序串算法(2)
- web标准---html、css、js分离
- 2015最新安卓例子自定义控件等分类源码免费下载
- python的对象探寻.