- (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:];
UILabel *currentLocation=[[UILabel alloc]initWithFrame:CGRectMake(, , , )];
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 还有许多属性,不仅仅可以给出当前位置,还可以给出其他信息,后续研究。。。。

最新文章

  1. Owin:“System.Reflection.TargetInvocationException”类型的未经处理的异常在 mscorlib.dll 中发生
  2. 《Java编程思想》学习笔记(二)——类加载及执行顺序
  3. linux lin命令
  4. arcgis engine 监听element的添加、更新和删除事件(使用IGraphicsContainerEvents)
  5. SQL INSERT INTO 语句
  6. [转载] 高流量大并发Linux TCP 性能调优
  7. STM32F4_USART配置及细节描述
  8. L001-老男孩教育-Python13期VIP视频-19节-pbb
  9. (转)Call to undefined function mb_convert_encoding()
  10. JS(六)
  11. poj3273 二分
  12. crm查询记录共享给了哪些人
  13. 使用 gridfs-stream 存储文件遇到的一个坑。
  14. android官方技术文档翻译——Android Lint
  15. python3+selenium框架设计07-unittest单元测试框架
  16. 大数据小白系列——MR(1)
  17. web机试
  18. hdu1686 Oulipo KMP/AC自动机
  19. https知识了解与javaweb中如何使用https
  20. FairyGUI学习

热门文章

  1. 使用spawn-fcgi管理php-cgi
  2. 【接口测试】Jenkins+Ant+Jmeter搭建持续集成的接口测试平台
  3. C# 检测程序运行时间的方法,Stopwatch类
  4. Construct Binary Tree from Preorder and Inorder Traversal [LeetCode]
  5. ModalPopup
  6. poj1192 最优连通子集(树形dp)
  7. BZOJ4049 [Cerc2014] Mountainous landscape
  8. SunSonic 3.0 ORM开源框架的学习
  9. C语言学习常识
  10. 跑马灯标记marquee