iOS8 之后出现一些新的配置

[self.manager requestWhenInUseAuthorization];
并且在info.plist文件中增加
NSLocationWhenInUseUsageDescription BOOL YES
NSLocationAlwaysUsageDescription 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

CoreLocation+MapKit系统定位(含坐标以及详细地址)的更多相关文章

  1. 根据高德API知道坐标获取详细地址信息

    /** * 根据坐标获取具体地址 * @param coor 坐标字符串 * @return */ public static String getAdd(String coor){ String u ...

  2. selenium使用location定位元素坐标偏差

    python+selenium+Chromedriver使用location定位元素坐标偏差使用xpath定位元素,用.location获取坐标值,截取网页截图的一部分出现偏差. 之所以会出现这个坐标 ...

  3. 系统定位在iOS8中的改变

    CLLocationManager这个系统定位的类在iOS8之前要实现定位,只需要遵守CLLocationManagerDelegate这个代理即可: - (void)startLocate {   ...

  4. [课程设计]Scrum 3.4 多鱼点餐系统开发进度(下单详细信息页面&会员信息页面)

    Scrum 3.4 多鱼点餐系统开发进度(下单详细信息页面&会员信息页面) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队 ...

  5. [课程设计]Scrum 3.3 多鱼点餐系统开发进度(下单详细信息页面设计)

    Scrum 3.3 多鱼点餐系统开发进度(下单详细信息页面设计)  1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队选题:餐厅到店点 ...

  6. 【Oracle RAC】Linux系统Oracle11gR2 RAC安装配置详细过程V3.1(图文并茂)

    [Oracle RAC]Linux系统Oracle11gR2 RAC安装配置详细过程V3.1(图文并茂) 2 Oracle11gR2 RAC数据库安装准备工作2.1 安装环境介绍2.2 数据库安装软件 ...

  7. 如何设置Linux(Centos)系统定期任务(corntab详细用法)

    如何设置Linux(Centos)系统定期任务(crontab详细用法) 1.Crontab简介 Linux 系统则是由 cron (crond) 这个系统服务来控制的.Linux 系统上面原本就有非 ...

  8. 【Oracle RAC】Linux系统Oracle12c RAC安装配置详细记录过程V2.0(图文并茂)

    [Oracle RAC]Linux系统Oracle12c RAC安装配置详细过程V2.0(图文并茂) 2 Oracle12c RAC数据库安装准备工作2.1 安装环境介绍2.2 数据库安装软件下载3 ...

  9. Deepin系统手动安装oracle jdk8详细教程

    Deepin系统手动安装oracle jdk8详细教程 oracle官网下载jdk压缩包,使用 sudo tar -zxf jdk***解压文件,我放在在了home/diy/java/jdk路径下. ...

随机推荐

  1. [C#] - 注入DLL

    原文:http://xyzlht.blog.163.com/blog/static/69301417200882834211787/ ) { MessageBox.Show("创建远程线程失 ...

  2. A Simple problem

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2497 题意:给出顶点数,边数及节点s,判断s是 ...

  3. (转载)用PHP正则表达式清除字符串的空白

    (转载)http://www.chinaz.com/program/2009/0220/67569.shtml 我们经常会处理来自用户输入或从数据库中读取的数据,可能在你的字符串中有多余的空白或制表符 ...

  4. 网络流(最大流):COGS 28 [NOI2006] 最大获利

    28. [NOI2006] 最大获利 ★★★☆   输入文件:profit.in   输出文件:profit.out   简单对比 时间限制:2 s   内存限制:512 MB [问题描述] 新的技术 ...

  5. DP(斜率优化):HDU 3507 Print Article

    Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)To ...

  6. QDomDocument Access violation writing location

    今天犯了一个非常2的错误! 为了将面板参数保存起来,选择用QDomDocument构造Dom树,然后用doc.toString()方法返回符合xml格式的QString.如: QString CutF ...

  7. 数据结构——N皇后放置方法种数

    Description 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上. 你的任务是,对于给定的N,求出有多少种合 ...

  8. Spring Boot 入门概念介绍

    使用spring-boot快速开发spring应用 转 http://itindex.net/detail/49108-spring-boot-%E5%BC%80%E5%8F%91 spring多年以 ...

  9. mysql5.5 对触发器,函数,存储引擎,事件进行主从复制情况.(转)

       mysql5.5 对触发器,函数,存储引擎,事件进行主从复制情况. 转(http://blog.csdn.net/m582445672/article/details/7670802) 一.My ...

  10. android-个性化进度条

    1.案例效果图 2.准备素材                                progress1.png(78*78)              progress2.png(78*78) ...