iOS8 之后出现一些新的配置

[self.manager requestWhenInUseAuthorization];并且在info.plist文件中增加NSLocationWhenInUseUsageDescription  BOOL YESNSLocationAlwaysUsageDescription         string “提示描述”记得加依赖库CoreLocation.framework   MapKit.framework

创建MapView

if (_mapView == nil) {_mapView = [[MKMapView alloc]initWithFrame:CGRectMake(0, 0, 0.5, 0.5)];//        _mapView.userTrackingMode = MKUserTrackingModeFollow;_mapView.delegate = self;_mapView.showsUserLocation = YES;[self.view addSubview:_mapView];
}

创建locationManager

if ([CLLocationManager locationServicesEnabled] == YES) {//判断定位是否可用_locationManager = [[CLLocationManager alloc]init];_locationManager.delegate = self;_locationManager.desiredAccuracy = kCLLocationAccuracyBest;//定位精确度_locationManager.distanceFilter = 10; //位置变化10米更新位置信息//NSLog(@"定位");if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)[_locationManager requestWhenInUseAuthorization];
}else{//NSLog(@"定位不可用");
}[_locationManager startUpdatingLocation];

CLLocationManager Delegate

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{//NSLog(@"%s",__FUNCTION__);[manager stopUpdatingLocation];NSLog(@"newLocation = %@",newLocation);NSLog(@"oldLocation = %@",oldLocation);//获取经度和纬度的结构体CLLocationCoordinate2D coordinate = newLocation.coordinate;//纬度信息,CLLocationDegrees类型实际上就是double型CLLocationDegrees latitude = coordinate.latitude;//经度信息,CLLocationDegrees类型实际上就是double型CLLocationDegrees longitude = coordinate.longitude;NSLog(@"%f,%f",latitude,longitude);[self.latitude setText:[NSString stringWithFormat:@"纬度:%lf",latitude]];[self.longitude setText:[NSString stringWithFormat:@"经度:%lf",longitude]];/*// 获取当前所在的城市名CLGeocoder *geocoder = [[CLGeocoder alloc] init];//根据经纬度反向地理编译出地址信息[geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *array, NSError *error){if (array.count > 0){CLPlacemark *placemark = [array objectAtIndex:0];//详细信息[self.address setText:[NSString stringWithFormat:@"地址:%@",placemark.name]];//获取城市NSString *city = placemark.locality;if (!city) {//四大直辖市的城市信息无法通过locality获得,只能通过获取省份的方法来获得(如果city为空,则可知为直辖市)city = placemark.administrativeArea;}[self.city setText:[NSString stringWithFormat:@"城市:%@",city]];}else if (error == nil && [array count] == 0){NSLog(@"No results were returned.");}else if (error != nil){NSLog(@"An error occurred = %@", error);}}];*/
}-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{NSLog(@"定位失败  ,%@",error);
}

MapView获得详细地址

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{CLLocation * newLocation = userLocation.location;self.lastCoordinate=mapView.userLocation.location.coordinate;NSUserDefaults *standard = [NSUserDefaults standardUserDefaults];[standard setObject:@(self.lastCoordinate.longitude) forKey:MMLastLongitude];[standard setObject:@(self.lastCoordinate.latitude) forKey:MMLastLatitude];CLGeocoder *clGeoCoder = [[CLGeocoder alloc] init];CLGeocodeCompletionHandler handle = ^(NSArray *placemarks,NSError *error){for (CLPlacemark * placeMark in placemarks){NSDictionary *addressDic=placeMark.addressDictionary;NSString *City=[addressDic objectForKey:@"City"];
//            NSString *subLocality=[addressDic objectForKey:@"SubLocality"];
//            NSString * adressName  = [NSString stringWithFormat:@"%@%@",subLocality,street];[self.city setText:[NSString stringWithFormat:@"城市:%@",City]];[self.address setText:[NSString stringWithFormat:@"地址:%@",placeMark.name]];[self stopLocation];}};[[NSUserDefaults standardUserDefaults] synchronize];[clGeoCoder reverseGeocodeLocation:newLocation completionHandler:handle];}

停止定位

-(void)stopLocation
{if (_mapView) {NSLog(@"关闭");_mapView.showsUserLocation = NO;[_mapView removeFromSuperview];_mapView = nil;}
}

  

 

来源: http://www.cnblogs.com/spaceID/p/4992167.html

转载于:https://www.cnblogs.com/spaceID/p/4992167.html

CoreLocation+MapKit系统定位(含坐标以及详细地址)相关推荐

  1. [转Iphone]根据经纬度坐标取详细地址(包括国,省,市,街道,号)

    获取当前手机地址,再从经纬度转换成详细地址(包括:国家名-国家代码,省,市,街道名,邮政代代码等). 1:获取当前手机经纬度 @implementation CurrentLocation @synt ...

  2. Kickstart无人值守安装系统(含DHCP超详细原理)

    前言: 为啥要用无人值守安装系统?很简单的答案!就两个! 一个是方便日常工作,另一个就是可以用来装逼! 常规装系统的办法有哪些? 光盘安装系统===>一个服务器DVD内置光驱百千块,百台服务器都 ...

  3. 百度地图api根据详细地址反查坐标

    用百度地图api根据详细地址反查坐标 /*** 根据详细地址反查坐标* @param args*/public static void main(String[] args) {String addr ...

  4. 苹果系统服务器状态在哪里,详细解读iPhone上的系统定位服务

    原标题:详细解读iPhone上的系统定位服务 自从GPS功能加入智能手机之后,世界仿佛一下子就变小了,只要手上拿着手机,似乎没有什么地方是我们所不能到达的.但GPS定位服务的出现也带来了隐私的安全问题 ...

  5. win10系统定位服务器地址,win10系统定位服务器地址

    win10系统定位服务器地址 内容精选 换一换 将NFS文件系统挂载到Windows IIS服务器时,报错路径格式不支持,挂载失败.IIS Web服务器的物理路径错误.根据可能原因进行故障排查.如图1 ...

  6. Android系统定位获取经纬度

    Android系统定位获取经纬度 直接上代码 public class LocaltionUtil {private double latitude = 0.0;private double long ...

  7. springBoot redis开发的Java快递代拿系统(含人脸识别,验证码登录)

     源码获取:我的博客资源页面可以下载!!!! 项目名称 springBoot redis开发的Java快递代拿系统(含人脸识别,验证码登录) 系统介绍 快递代拿系统 > 该项目使用当前最为流行的 ...

  8. 基于Jsp、Java、数据库、HTML实现网上投票系统(含文档和代码)Jsp课程设计

    目录 摘要 第1章 课程设计内容及要求 第2章 系统分析 2.1 系统简介 2.2 系统功能 第3章 系统设计 3.1 开发工具简介 3.2 总体功能模块设计 第4章 系统实现 4.1 数据库实现 4 ...

  9. **Hadoop Ubuntu系统搭建攻略全详细!!!附带Hadoop搭建成功后测试案例**

    Hadoop Ubuntu系统搭建攻略全详细!!!附带Hadoop搭建成功后测试案例 Hadoop搭建教程 一.需要安装的工具: 1.首先确保虚拟机能连上网. 2.更新源列表: sudo apt-ge ...

最新文章

  1. 1.Spring Security 详细简绍与入门
  2. 【重磅干货】Python、机器学习、深度学习算法实战和应用必备书籍
  3. linux命令nohup
  4. spring cloud 2.3.x 注册中心eureka 配置
  5. english email writing techniques demo
  6. hiho1249 Xiongnu's Land
  7. 组合数据类型练习,英文词频统计实例9-21
  8. Redis添加主节点
  9. Java集合(实现类线程安全性)
  10. ps背景不变换字_PS教程:复杂背景中,如何利用通道轻松抠出发丝?
  11. 【苹果cms10 Maccmsv10 站群深度定制版 开发日志】 数据渲染模块
  12. linux下mysql-5.5.15安装详细步骤
  13. Apache软件基金会Member陈亮:一名开源拓荒者的 Apache之旅
  14. 一对一培训之视频免费分享-2017-12-09-第 03 阶段-准备-基础-架构-课件
  15. java 递归_两篇文章带你了解java基础算法之递归和折半查找
  16. 工具的使用——vs2013
  17. 数据结构(二):线性表的使用原则以及链表的应用-稀疏矩阵的三元组表示
  18. windows安装 wget
  19. 二叉树非递归遍历思路总结
  20. 项目计划书——书写模板

热门文章

  1. 怎么找出消耗 CPU 的罪魁祸首?!
  2. 动图 + 源码,演示 Java 中常用数据结构执行过程及原理
  3. 帮你理清 SpringBoot 与 SpringMVC 的关系
  4. 通俗说基于Yarn的Map-Reduce过程
  5. Java 8系列之Stream的强大工具Collector
  6. Spring Cloud构建微服务架构:服务消费(Feign)【Dalston版】
  7. 海量数据处理:BitMap
  8. 青少年蓝桥杯_2020_steam考试_初级组_第二题
  9. An error happened during template parsing (template: class path resource [templates/emp/list.html]
  10. Android --- 消息模式Toast.makeText.show()的几种用法总结