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# IOCP服务器

    C# IOCP服务器 @by  群63438968 这是我写的unity 网络斗地主的服务器源码,本来我想只公开部份服务端代码的,但是为了回报大家的热情,以及曾经和现在的好兄弟,我计划慢慢开源! 告诉 ...

  2. websphere安装和mvn dependency:copy-dependencies

    http://www.blogjava.net/paulwong/archive/2009/09/19/295657.html http://ljhzzyx.blog.163.com/blog/sta ...

  3. autotrace显示Statistics很多信息为0(转)

    一朋友使用autotrace查看数据库执行计划发现结果如下,Statistics中很多信息为0,这个肯定是不正常现象,什么都可以为0,consistent gets也不可能为0. SQL> se ...

  4. Wine install, 卸载的方法

    EL6 (RHEL6 and SL6) Required packages for proper building of 32-bit Wine on 64-bit EL6 yum install - ...

  5. 数据结构(左偏树):HDU 1512 Monkey King

    Monkey King Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  6. [Locked] Missing Ranges

    Missing Ranges Given a sorted integer array where the range of elements are [lower, upper] inclusive ...

  7. 金牌分析师助力 鲁泰A图谋再造一个“鲁泰”?_财经_中国网

    金牌分析师助力 鲁泰A图谋再造一个"鲁泰"?_财经_中国网 金牌分析师助力 鲁泰A图谋再造一个"鲁泰"?

  8. 想挑战AlphaGO吗?先和PostgreSQL玩一玩?? PostgreSQL与人工智能(AI)

    1月4日晚,随着古力认输,Master对人类顶尖高手的战绩停留在60胜0负1和,而令人尴尬的是这唯一一场和棋还是因为棋手掉线系统自动判和,并不是棋盘上的局势真的势均力敌了.包括聂卫平.柯洁.朴廷桓.井 ...

  9. js~fancybox为我们提供的iframe功能

    对于fancybox我们已经耳熟能详了,一般用来到表单的弹框,提示弹框等,而今天,我们将分页列表也使用fancybox来实现一下,这东西听起来简单,但做起来还真不是那么回事,有事细节需要我们注意的,首 ...

  10. DirectX 11游戏编程学习笔记之8: 第6章Drawing in Direct3D(在Direct3D中绘制)(习题解答)

            本文由哈利_蜘蛛侠原创,转载请注明出处.有问题欢迎联系2024958085@qq.com         注:我给的电子版是700多页,而实体书是800多页,所以我在提到相关概念的时候 ...