pray例子----------------------获取地理位置


[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. #import <CoreLocation/CoreLocation.h>  
  2.   
  3. @interface PBTextViewController ()<CLLocationManagerDelegate>  
  4.   
  5. @property (weak, nonatomic) IBOutlet UIImageView *bkImageView;  


[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. _locationManager = [[CLLocationManager alloc] init];  
  2. _locationManager.delegate = self;  
  3. _locationManager.desiredAccuracy = kCLLocationAccuracyBest;  
  4. _locationManager.distanceFilter = 1000.0f;  




[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. #pragma mark---- location  
  2. - (void)startUplocation  
  3. {  
  4.     if ([CLLocationManager locationServicesEnabled])  
  5.     {  
  6.         [_locationManager startUpdatingLocation];  
  7.     }  
  8.     else  
  9.     {  
  10.         UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请开启定位功能!"delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil nil];  
  11.         [av show];  
  12.     }  
  13. }  
  14.   
  15. #pragma mark - CLLocationManagerDelegate  
  16. // 地理位置发生改变时触发  
  17. - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation  
  18. {  
  19.     // 获取经纬度  
  20.     NSLog(@"纬度:%f",newLocation.coordinate.latitude);  
  21.     NSLog(@"经度:%f",newLocation.coordinate.longitude);  
  22.     // 停止位置更新  
  23.     [manager stopUpdatingLocation];  
  24.     CLGeocoder* geocoder = [[CLGeocoder alloc] init];  
  25.       
  26.     [geocoder reverseGeocodeLocation: newLocation completionHandler:^(NSArray *array, NSError *error) {  
  27.         if (array.count > 0)  
  28.         {  
  29.             CLPlacemark *placemark = [array objectAtIndex:0];  
  30.             NSString *city = placemark.locality;  
  31.             NSString *street = placemark.thoroughfare;  
  32.             NSLog(@"%@,%@",city,street);  
  33.             NSMutableString *ms = [[NSMutableString alloc] init];  
  34.             [ms appendString:city];  
  35.             [ms appendString:street];  
  36.             _locationLb.text = ms;  
  37.         }  
  38.     }];  
  39. }  
  40.   
  41. // 定位失误时触发  
  42. - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error  
  43. {  
  44.     NSLog(@"error:%@",error);  
  45. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MyObject-C

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值